JSON5
Overview
JSON5 parser and query language
JSON5 is a superset of JSON that allows comments, unquoted keys, single-quoted strings, trailing commas, and a few other ergonomic relaxations. Notch ships a JSON5 parser and a small query language for navigating the parsed tree, both in the package edu.montana.notch.json5.
What ships
JSON5Parser- parse a JSON5 source string into a tree ofJSON5Value.JSON5Valuehierarchy - a sealed type tree with concreteJSON5Object,JSON5Array,JSON5String,JSON5Number(split intoJSON5IntegerandJSON5Decimal),JSON5Boolean, andJSON5Nullcases.QueryParserandQueryEngine- a tiny path expression language for pulling values out of a parsed tree.
Why JSON5
Plain JSON is strict by design. JSON5 is more pleasant to author and read by hand:
{
// comments are allowed
name: 'notch',
versions: [
1, 2, 3, // trailing commas are fine
],
unquoted: true,
}
Notch uses JSON5 anywhere it loads structured data that humans might write directly: configuration, fixtures, examples.
See also
- Parsing JSON5 for the parser API.
- Value Types for the value hierarchy.
- Query Language for path expressions.