unsafe-json
unsafe json serializer, but fast.
Installation
npm i unsafe-json -S
Usage
; ; ; ;;console.logstr;console.logparsestr;
Api
.build(schema: any, strict = true): (obj: any) => string
to squeeze a little bit more performance, set strict = false
, it will not dispose type of undefined
.parse(jsonStr: string)
like JSON.parse
Performance
tests on my PC: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
- simple object, ~8X faster (strict=false)
{"a":1,"b":"hello","c":{"x":1,"y":"zzzzzz"}}
------- performance comparation -------
native stringify: 68.610ms
unsafe stringify: 8.842ms
native parse: 103.864ms
unsafe parse: 42.718ms
- object with array, ~3X faster
{"a":1,"b":"hello","c":{"x":1,"y":"zzzzzz"},"d1":["asd","aaaaaa","asdasdasd"],"d":[{"x":1,"y":"zzzzzz"},{"x":1,"y":"zzzz"},{"x":1,"y":"z"}]}
------- performance comparation -------
native stringify: 188.564ms
unsafe stringify: 66.726ms
native parse: 252.536ms
unsafe parse: 72.011ms
Todo
- xxx
License
MIT