Forum Discussion
That's the only way since your string is definitely not valid JSON. You need it to look like this:
{"language": "Tamil", "taskId": 123}
- jfpelletier10 months agoContributor
Hello again, ptaylor,
Actually, there is an issue with this...
I took the results below from the Expression Builder. You can see at line 31 that I'm doing all the replacements on all the items in the list (3 elements labelled each "German", "French (Europe)" and "Italian"). At line 32 you can see after the .parse method that my JSON after parsing has only one element now (labelled "German"). So I'm losing everything except the first entry.
31: ([jsonPath($, "$sameLanguage[*].REQUESTEDLANGUAGES").toString().replaceAll('=', '" : "').replaceAll('},{', '"},{"').replaceAll(', ', '", "').replace(/^{/, "{\"").replace(/}$/, "\"}")].toString()): { jsonEncodedString: "{"language" : "German", "taskId" : "43251-1-2"},{"language" : "French (Europe)", "taskId" : "43251-1-3"},{"language" : "Italian", "taskId" : "43251-1-4"}" } 32: .parse: [ { language:"German" taskId:"43251-1-2" } ]
Can you see what I'm doing wrong to have this bad results?
Thanks!
JF
- jfpelletier10 months agoContributor
Hello ptaylor,
I've found a better solution by doing the fixing at the source. The reason why that JSON was badly formatted is because it was a "real" JSON that has been saved as a string in a DB using the .toString() method. I changed to use JSON.stringify() instead, and converting it back to JSON after DB retrieval works much better now, no need to use any string replacements. 🙂
JF