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

Find a better JSON parser or implement our own #646

Open
schani opened this issue Mar 8, 2018 · 12 comments
Open

Find a better JSON parser or implement our own #646

schani opened this issue Mar 8, 2018 · 12 comments
Labels
good first issue Not necessarily easy, but doesn't require deep quicktype knowledge

Comments

@schani
Copy link
Member

schani commented Mar 8, 2018

Required features:

  • Streaming. We need to process files larger than V8 strings allow.
  • Preserve property order.
  • Good and actionable error messages. Our users often have issues with invalid JSON.
  • Recover from common errors.
  • Distinguish between integers and floating point numbers.
  • Span for each non-symbol token - line number and column of start and end.

Common errors:

  • Unquoted keys: { foo: "bar" }
  • Superfluous commas: [1, 2, 3,]
  • Wrong delimiter: [ "foo": "bar" ], { 1, 2, 3 }

Other easily recoverable errors:

  • = (or anything else) instead of : in objects: { "foo"="bar" }
  • Number format stuff, such as no digits before point (.3), leading zeros (0123), hexadecimals (0xdeadbeef)
@schani schani added the good first issue Not necessarily easy, but doesn't require deep quicktype knowledge label Mar 8, 2018
@dvdsgl
Copy link
Member

dvdsgl commented Mar 8, 2018

And perhaps support some extensions to JSON:

  • Comments
  • Tuples (e.g. <1, 2>)
  • Explicit maps (e.g. <"name": "David">

@schani
Copy link
Member Author

schani commented Mar 8, 2018

I'm not aiming to extend JSON, or make it suitable as a language for specifying schemas. I still think the proper way for that is via a graphical editor. I do agree that we shouldn't trip up on comments, but they should still be marked as errors.

@dvdsgl
Copy link
Member

dvdsgl commented Mar 8, 2018

Sounds good to me.

@sgvictorino
Copy link
Contributor

@szotp
Copy link

szotp commented Oct 10, 2018

Treating 1.0 as Int has bitten me in the ass today, any workaround for this?

@dvdsgl
Copy link
Member

dvdsgl commented Oct 10, 2018

Our CLI and IDE plugins do not do this. You can use them for now as a workaround.

@dvdsgl
Copy link
Member

dvdsgl commented Oct 10, 2018

@szotp we are publishing a fix, it should be live in 15 minutes.

@yepher
Copy link

yepher commented Nov 21, 2018

Have you considered porting jq as your JSON parser?
* Project: https://stedolan.github.io/jq/
* GoLang Port: https://github.com/savaki/jq

@schani
Copy link
Member Author

schani commented Nov 21, 2018

jq is written in C, unless I’m not mistaken, and we need to run in the browser. I also don’t know whether it has all the features we’re looking for.

I know, WASM is an option, but between extracting the parser from jq, integrating WASM and making the build work, I’d bet it’s less work to implement our own, and it’d be exactly what we want, too.

@thesoftwarephilosopher
Copy link

Is this issue the reason that quicktype fails to generate a TypeScript file for my 4.9 MB file that has 200k lines?

@thesoftwarephilosopher
Copy link

Possibly related? microsoft/TypeScript#42761

@undirectlookable
Copy link

JSON with comments (aka jsonc) is nice to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Not necessarily easy, but doesn't require deep quicktype knowledge
Projects
None yet
Development

No branches or pull requests

7 participants