Decode broken JSON.
Custom type for JSON values.
Mostly this is self-explanatory, but numbers might be interesting because no
effort is made to convert them to Float values. This means you can deal with
overflows or precision mismatches in broken JSON.
A parser for a JSON value is:
Parser.oneOf [ object, array, string, number, true, false, null ]According to the [specification][rfc7159], a JSON document is optional
whitespace, a JSON value (that oneOf … expression above), then more optional
whitespace – and that's what the json parser does. Hence parsing a compliant
JSON document is nothing more than:
Parser.run json "…"Use these building blocks to compose a parser for broken JSON as you need. If
you need to parse non-compliant quoted strings, for example, it might be best to
copy just the string code from this module into your project, and use the
other parsers in this module – object, array, and so on – to compose a new
parser.
Parser for a quoted JSON string.
string and some of its helpers have been adapted from elm/parser's
DoubleQuoteString example.
Does the number have a fractional component?
i.e. the optional part after the decimal point.
Does the number have an exponent?
i.e. an optional suffix starting with e or E in the number.
The sign of the exponent.
Parse the given JSON string.
Errors come straight from elm/parser and may not be super useful. It may be worth changing this parser to use elm/parser's
Parser.Advancedwhich allows more control over errors.