https://github.com/antonmedv/fast-json
Fast extraction of part of JSON
https://github.com/antonmedv/fast-json
Last synced: 10 months ago
JSON representation
Fast extraction of part of JSON
- Host: GitHub
- URL: https://github.com/antonmedv/fast-json
- Owner: antonmedv
- License: mit
- Created: 2018-09-16T15:40:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-22T06:42:22.000Z (over 6 years ago)
- Last Synced: 2025-03-18T04:56:32.471Z (10 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 57
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fast-json
This package implements fast extraction of part of JSON.
* 3.5x times faster than jq
* 4.5x times faster than JSON.parse
Notes:
* Fastest way of extracting part of JSON from file
* Arrays not supported currently
* Does not check for valid JSON (you can grab "foo" from here: `{"foo": "bar", here goes anything`)
## Install
```bash
npm i @medv/fast-json
```
## Usage
```js
const fastJSON = require('@medv/fast-json')
const result = fastJSON(input, path)
```
Another example:
```js
const result = fastJSON('{"foo": {"bar": 1}}', ['foo', 'bar'])
```
## CLI
```bash
npm i -g @medv/fast-json
```
```bash
cat data.json | fast-json path to field
```
## Benchmarks
Benchmarks were made with [hyperfine](https://github.com/sharkdp/hyperfine) on a big json (around 400mb).
```
Benchmark #1: cat data.json | fast-json gates aeroflot_ndc_gate gates_info airline_iatas
Time (mean ± σ): 4.080 s ± 0.181 s [User: 3.206 s, System: 1.205 s]
Range (min … max): 3.877 s … 4.292 s
Benchmark #2: cat data.json | jq .gates.aeroflot_ndc_gate.gates_info.airline_iatas
Time (mean ± σ): 14.938 s ± 0.198 s [User: 13.009 s, System: 2.170 s]
Range (min … max): 14.808 s … 15.347 s
Benchmark #3: cat data.json | fx .gates.aeroflot_ndc_gate.gates_info.airline_iatas
Time (mean ± σ): 18.443 s ± 0.356 s [User: 17.495 s, System: 2.661 s]
Range (min … max): 17.731 s … 19.179 s
```
# License
MIT