1.0.0 • Published 5 years ago

json-parser-ts v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

json-parser-ts

npm version CI

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))
1.0.0

5 years ago

0.1.2

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago