Javascript Agent JSON.parse is throwing an exception, but the same string can be parsed correctly in the browser
Because I need on_change and extract, I used the Website Agent and get the following events (The original event was too long, so I manually condensed it to ensure readability)
{
"content":"{\"id\":1000,\"des\":\"Here is the introduction!\\n1.Here is the introduction2!\",\"title\":\"Here is the title\"}"
}
In the browser enviroment, using JSON.parse(json.content) can correctly parse
In the Javascript Agent,
JSON.parse(event['payload'].content) will get JavaScript error: SyntaxError: Unexpected token
I guess this might be related to escape characters, and the V8 engine in the browser handles this more effectively. So I tried using
.replace(/\n/g,"\\n")
which worked, but simply using "replace" still doesn't seem good enough. Are there any other methods to better parse a string?
The only thing I got to work was the Jq Agent. It would be something like this:
{
"filter": "[ .content | fromjson ]"
}
The only thing I got to work was the Jq Agent. It would be something like this:
{ "filter": "[ .content | fromjson ]" }
Thank you for your response, but this still won't work. Jq agent displaying an error "Invalid string: control characters from U+0000 through U+001F must be escaped"
The issue might be related to escaped characters. \\n