json-parser-ts
v1.0.0
Published
A type-safe combinator-based JSON parser
Downloads
2
Maintainers
Readme
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-ts
Interfaces
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))