convert string into Object (key value pairs) | Community
Skip to main content
Adobe Employee
May 3, 2024
Question

convert string into Object (key value pairs)

  • May 3, 2024
  • 1 reply
  • 563 views

I have a string like this "*test1:*value1 *test2:* value2 *test3:**test4:*value4" I need to convert into JSON object(key-value pairs) in the below-shown structure.

output: { "test1":"value1",

              "test2":"value2",

               "test3":"";

              "test4":"value4"}

when there is no value after the key, it must be replaced with the empty string.

Please help me with this.

thanks in advance.. 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Level 5
May 3, 2024

Use a Transform to JSON or Create JSON module as your basis, but you'll need to deal with parsing your input stream appropriately.  Things like split or regular expressions will help you with that.  The empty string could be done using ifempty(value; emptystring).