Skip to content

node-labx/graceful-json-parse

Repository files navigation

Install

npm install graceful-json-parse

API

1、jsonParse(jsonString[, options])

Parameters

  • jsonString: The string to parse as JSON.
  • options(optional)
    • options.reviver: If a function, this prescribes how the value originally produced by parsing is transformed, before being returned. more info about this param in here

Return value

object {error, data}

  • error: should be an Error object in case of error or undefined in case of success
  • data: should be the object corresponding to the given JSON text or undefined in case of error

Example

const jsonParse = require("graceful-json-parse");

const result = jsonParse("{}");

2、jsonParse(jsonString[, options])

The parameters and return value is the same as above.

const jsonParse = require("graceful-json-parse/tuple");

const [error, data] = jsonParse("{}");

3、jsonParse(jsonString[, options], callback)

The parameters and return value is the same as above.

const jsonParse = require("graceful-json-parse/callback");

jsonParse("{}", function (error, data) {
  // your code
});

About

Graceful json parse

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors