cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Turning Embedded JSON into Data

pcoleman
New Contributor III

Hiโ€ฆI have a REST get that returns the following as part of itโ€™s payload:
image

Not sure what the right approach is, but I ultimately want to take that JSON that comes back as text in that $ field and turn it into documents. Not sure if I should be looking at the map() function or what. Any thoughts?

10 REPLIES 10

bojanvelevski
Valued Contributor

Hey @pcoleman,

Can you send a sample of the response? Even
a small chunk would be enough.

image
Hereโ€™s an image of the response. Itโ€™s basically JSON embedded in an xml.

j_angelevski
Contributor III

Hi @pcoleman,

The following expression

JSON.parse(jsonPath($, "entity.feed.entry[*].content['$']"))

should be enough to parse the JSON string, you donโ€™t need to replace the \n characters.

Unfortunately, it gives me the following when I try that. It seems to somehow interpret it as a list.
โ€œerrorโ€:
โ€œExpecting a string argumentโ€

Most likely the JSON.parse() method recieved an array instead of string.
If your content itโ€™s always on the same index in your entry array, you can use the following expression

JSON.parse($entity.feed.entry[2].content['$'])

or

JSON.parse(jsonPath($, "entity.feed.entry[*].content['$']").toString())