Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/fast-json-parse
The fastest way to parse JSON safely
https://github.com/mcollina/fast-json-parse
Last synced: 1 day ago
JSON representation
The fastest way to parse JSON safely
- Host: GitHub
- URL: https://github.com/mcollina/fast-json-parse
- Owner: mcollina
- License: mit
- Created: 2016-02-22T07:26:10.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-09T21:16:20.000Z (almost 3 years ago)
- Last Synced: 2024-12-14T10:04:31.764Z (9 days ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 88
- Watchers: 5
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fast-json-parse
[![Build Status](https://travis-ci.org/mcollina/fast-json-parse.svg)](https://travis-ci.org/mcollina/fast-json-parse)
It is equivalent to [json-parse-safe](http://npm.im/json-parse-safe),
but it set both the `err` and `value` property to null.The reason why this is fast is that `try/catch` inhibits the functions
in which you use them to be optimized. This assumption holds true up to
Node 6, from Node 7 and forward this module is not useful anymore.## Install
```
npm i fast-json-parse --save
```## Usage
You can use it as a function or via a contructor, as you prefer.
### function
```js
'use strict'var parse = require('fast-json-parse')
var fs = require('fs')var result = parse(fs.readFileSync('./package.json', 'utf8'))
if (result.err) {
console.log('unable to parse json', result.err.message)
} else {
console.log('json parsed successfully', result.value)
}
```### constructor
```js
'use strict'var Parse = require('fast-json-parse')
var fs = require('fs')var result = new Parse(fs.readFileSync('./package.json'))
if (result.err) {
console.log('unable to parse json', result.err.message)
} else {
console.log('json parsed successfully', result.value)
}
```## Acknowledgements
fast-json-parse is sponsored by [nearForm](http://nearform.com).
## License
MIT