json-parsers

Monorepo containing research for various json-parsers

BSD-3-CLAUSE License

Stars
3

JavaScript JSON parsers

Monorepo containing research for various JSON parsers for JavaSript.

Requirements

I consider quality JSON parser to support source maps and implements error recovery mechanism.

This is the list of researched JSON parsers. Clicking on specific json parser will lead you to specific research whitepaper of that particular parser.

Other JSON parser

This list contains parsers that seemed worth analyzing but after initial analysis lacked features I'd expect from the proper parser:

  • parsimmon - very primitive, no location, nor error recovery mechanism
  • Hand-build parser
  • PEG.js - no advanced JSON grammar available (no location, no error recovery)
  • jison - seems dead (no commits for 3 years), error recovery in alpha mode
  • nyma - usage in community is minimal, documentation consist of 1 A4 document
  • ohm.js - sparse documentation, no release in 2 years, no mention about error recovery mechanism

Summary

This section describes candidates of JSON parsers that got into final selection. The order that the libraries are mentioned in doesn't express any preference.

One of the most interesting parsers (not a parser generator) that I've researched here is jsonc-parser developed by Microsoft. It's really a piece of art, with no dependencies, advanced error recovery mechanism and source maps support. It also goes beyond the JSON spec and optionally supports JS comments and trailing commas. Contains API for incremental parsing and edits.

The rest of the parsers that got into this selection falls into categories of true parser generators. tree-sitter, Chevrotain and Antlr4 are on the same level feature-vise.

Chevrotain seems like most configurable one, allowing switching the fault tolerance/error recovery mechanism on and off, along with optional parsing of comments and switching between CST and AST trees. It's also the fastest (JavaScript) parser generator out there.

Antlr4 is a very mature library with JavaScript runtime, considered a second fastest out there. It's masterfully documented and there is an actual book written about it. Error recovery strategies can be altered.

tree-sitter supports incremental parsing, AST updates and has one of the most sophisticated error recovery mechanism out there. The library is super fast as is written in C and can be used via node.js bindings or WASM. The biggest thing about this library is that Github uses it to highlight all it's code and Atom editor uses it as well. Error recovery mechanism cannot be turned off by a configuration.

Additional resources