A combinator-based JSON parser.
It's RFC 8259 compliant, well tested using dataset from JSONTestSuite
npm i json-parser-ts
import * as J from 'json-parser-ts'
const res = J.parse(jsonStr)
The parse function returns E.Either<Err, JSON>
, while JSON is parsed as nested tagged union, see model.ts for detail
export type JSON =
| JSONObject
| JSONArray
| JSONString
| JSONNumber
| JSONBoolean
| JSONNull
The lib also provides a flatten
function to transform nested tagged union back to flat JavaScript object.
import * as J from 'json-parser-ts'
import { pipe } from 'fp-ts/lib/function'
import * as E from 'fp-ts/lib/Either'
const res = pipe(J.parse(jsonStr), E.map(J.flatten))