Promise based JSON parser. Handles invalid JSON data gracefully.
npm install json-promise 
Parse and stringify JSON data using promise to gracefully
handle success and failures if the data is invalid. See the
examples below for usage instructions. This module use bluebird
for Promise/A+ support.
javascript
var json = require('json-promise');
var str = [
'{"menu":{"id":"file","value":"File","popup":'
,'{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},'
,'{"value":"Open","onclick":"OpenDoc()"},{"value":"Close",'
,'"onclick":"CloseDoc()"}]}}}'
].join('');json.parse(str)
.then(function onParse(obj) {
// do something with the data object
})
.catch(function onParseError(e) {
// the data is corrupted!
});
`$3
`javascript
var json = require('json-promise');
var obj = {
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{
"value": "New",
"onclick": "CreateNewDoc()"
},
{
"value": "Open",
"onclick": "OpenDoc()"
},
{
"value": "Close",
"onclick": "CloseDoc()"
}
]
}
}
};json.stringify(obj)
.then(function onStringify(obj) {
// do something with the string
})
.catch(function onStringifyError(e) {
// the data is corrupted!
});
``