Package Exports
- json-parse
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-parse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
json-parse
Curried function that calls
JSON.parse
on provided input returning either the parsed JSON or the specified default value if the data fails to parse as valid JSON instead of throwing aSyntaxError
.
npm install json-parse --save
You can also use Duo, Bower or download the files manually.
npm stats
Overview
Similar to try { return JSON.parse } …
but more functional and compositionally friendly.
API Example
Basic
var parse = require('json-parse')
parse([])('[1,2,3]')
//=> [ 1, 2, 3 ]
parse([])('[1,2,3')
//=> []
Pointfree Style
var parse = require('json-parse')
Promise.resolve('[1,2,3]')
.then(parse([]))
.then(sum)
//=> 6
Promise.resolve(undefined)
.then(parse([]))
.then(sum)
//=> 0
API
parse(defaultValue, data)
arguments
defaultValue (*)
Default value to return if given data does not parse as valid JSON.data (*)
Data to parse as JSON.
returns
(*)
JavaScript value corresponding to parsed data.
Alternatives
Contributing
SEE: contributing.md