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

failure to parse key/value strings containing $ character #318

Closed
combinadic opened this issue Mar 3, 2021 · 1 comment
Closed

failure to parse key/value strings containing $ character #318

combinadic opened this issue Mar 3, 2021 · 1 comment

Comments

@combinadic
Copy link

Greetings.
When trying to parse <script type = text/javascript>...</script> that contains the $ character JSON.parse() produces the following output:

JSON.parse("""{
"this": ["is", "json"],
"numbers": [85, 16, 12.0],
"and": [true, false, null],
"but not": ["1", 2,"$3.00"]}""")
ERROR: syntax: invalid interpolation syntax: "$3"
Stacktrace:
[1] top-level scope at none:1

However, removing the "$" from the last key/value pair produces the expected result.
Have I overlooked something in the JSON.parse() syntax?
Short of replace(ing)() the "$" with something like "AUD" character in pre-processing, is there some other workaround?
Thank you.

@KristofferC
Copy link
Member

KristofferC commented Mar 3, 2021

Writing a $ in a string literal is Julia syntax for interpolating something into the string (see https://docs.julialang.org/en/v1/manual/strings/#string-interpolation). You can see that you get the error, even if you remove the JSON.parse part. The solution is to either escape the $ (via \$) or use a raw string (via raw"""... $3.00...""").

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