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

Parsing a dubious JavaScript/JSON file #292

Open
cormullion opened this issue Sep 17, 2019 · 2 comments
Open

Parsing a dubious JavaScript/JSON file #292

cormullion opened this issue Sep 17, 2019 · 2 comments

Comments

@cormullion
Copy link

I was deep in a rabbit hole trying to parse a JavaScript file that defined a JSON object. I found an easy way to reproduce it on a mac:

using LazyJSON, JSON
s = read("/Applications/Julia-1.1.app/Contents/Resources/julia/share/doc/julia/html/en/search_index.js", String)
s = replace(s, "var documenterSearchIndex =" => "" )
jsoncontents1 = LazyJSON.parse(s)
jsoncontents2 = JSON.parse(s)

JSON.jl complains about a backslashed ':

ERROR: LoadError: Invalid escape sequence
Line: 15
Around: ...se Julia\'s compiler is differ...

I thought at first that this may well be the correct thing to do. But when I tried LazyJSON, it parsed without errors, which made me think that it might be OK. I spent a few minutes searching the internet but couldn't work out whether a \' was OK or not...

So I'll let you decide if this is a bug! :)

@kmsquire
Copy link
Contributor

Strictly speaking, this isn't valid JSON--escape (\) can only be followed by a specific set of characters (see http://json.org/).

Whether or not we want to support passing this anyway I'd another question. I would be open to it, perhaps with an additional keyword argument (e.g., strict=false)

(You also might want to check out JSON3.jl)

@cormullion
Copy link
Author

Thanks! A less strict option is always nice for the users, particularly when working on the fringes of the standards (talk to anyone working with Markdown...!).

I get a similar-ish problem with JSON3.jl (albeit with a different file):

 JSON3.read(filecontents)
ERROR: ArgumentError: invalid JSON at byte position 631241 while parsing type Any: InvalidChar
ntegrator.qold\nend"
},

]}

so I'll stay with LazyJSON for working with my malformed stuff, for now.

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