Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript Agent JSON.parse is throwing an exception, but the same string can be parsed correctly in the browser #3348

Open
tempppabx1 opened this issue Feb 5, 2024 · 2 comments

Comments

@tempppabx1
Copy link

tempppabx1 commented Feb 5, 2024

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
image
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?

@virtadpt
Copy link
Collaborator

virtadpt commented Feb 5, 2024

The only thing I got to work was the Jq Agent. It would be something like this:

{
    "filter": "[ .content | fromjson ]"
}

@tempppabx1
Copy link
Author

tempppabx1 commented Feb 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants