Expand my Community achievements bar.

Do you have questions about the migration to Adobe Business Platform? Come join our upcoming coffee break and ask away!

convert string into Object (key value pairs)

Avatar

Employee

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.. 

 

1 Reply

Avatar

Level 5

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).