Better JSON
Simply better json with comments and auto normalization. You can either use it as a new object, or override the default JSON object.
- comments are removed from strings
- quotes are added where needed automatically
- single quotes are corrected to double, when needed
- types are auto corrected ('1' becomes 1)
- trailing commas are removed
- crash resistance (runs in a try catch block, and returns null on error)
Installation
npm install @aspiesoft/better-json
Setup
const json = require('@aspiesoft/better-json');
// or to override the JSON object
require('@aspiesoft/better-json')();
Usage
json.parse(`
{
option1: string,
//option2: true, /* commented out */
option3: true,
}
`);
// expected output: {option1: 'string', option3: true}
json.stringify({test: 2, unwantedFunction: function(){}});
// expected output: {"test": 2}