Skip to content

wddwycc/json-parser-ts

Repository files navigation

json-parser-ts

npm version CI

A combinator-based 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))

About

A combinator-based JSON parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published