Turning Embedded JSON into Data

Hi…I have a REST get that returns the following as part of it’s payload:

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?

OK. I finally got this to work, but the method I used seems kind of overlong and hacky. First I took the input and ran it through this:
JSON.stringify(jsonPath($, "entity.feed.entry[*].content['$']")).replaceAll('\\n','').replaceAll('\\','').replaceAll('"{','{').replaceAll('}"','}')
This cleaned up the string to look like clean JSON minus the \n, escape and extra quote characters.
After this I turned it into a document and read it back in and used a JSON parser.

This worked, but I’m not really happy with the method. Is there any sort of clean function that takes control characters and escapes and just scrubs them? I’ve seen payloads in the past that come in a single field in a REST call and it seems like I’m doing a lot of extra and unnecessary work if I have to write it to disk just to read it back in.

Realized I can skip the File Writing by doing a JSON.parse() on the whole thing. Still seems like there should be a better way.

JSON.parse(JSON.stringify(jsonPath($, "entity.feed.entry[*].content['$']")).replaceAll('\\n','').replaceAll('\\','').replaceAll('"{','{').replaceAll('}"','}'))

Hey @pcoleman,

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

Hi Paul,

Good day, have you tried to set the Response Entity Type to BINARY in the REST Get snap?

then followed by a mapper with an output view as binary setting up the $content object in prep for writing


If you want to stream the document, use JSON parser snap instead of a File Writer snap

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.
“Expecting a string argument”

Here’s an image of the response. It’s basically JSON embedded in an xml.

I’ve done that before, but I don’t think it will work in this case because the entity is a whole lot more than just that JSON. I’ll give it a try though. If they were only sending that code as the entity, then I think I’d be ok. I think the mixed modes (xml with embedded JSON) of this data is rightfully causing an issue.

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(jsonPath($, "entity.feed.entry[*].content['$']").toString())
1 Like

This worked, though I needed to preface this with a JSON Splitter. Clearly I overcomplicated this. Thank you!