1.0.0 • Published 5 years ago
json-parser-ts v1.0.0
json-parser-ts
A type-safe combinator-based native JSON parser.
It's RFC 8259 compliant, well tested using dataset from JSONTestSuite
Install
npm i json-parser-tsInterfaces
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
| JSONNullThe 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))