JSON parser built in JS that can
- Build an AST for JSON
- Parse json text to JS object
NOTE: Its not for production
npm i js-nasty-json-parser
const { Parser } = require('js-nasty-json-parser/parser');
const p = new Parser(`{"name": "Json Parser"}`)
console.log(p.parse())
/** output **/
{
"type": "Object",
"body": [
{
"type": "PropertyExpression",
"key": {
"type": "StringLiteral",
"value": "name"
},
"value": {
"type": "StringLiteral",
"value": "Json Parser"
}
}
]
}
const { JsonBuilder } = require('js-nasty-json-parser/builder');
const b = new JsonBuilder()
console.log(b.build(`{"name": "Json Parser"}`));
/** output **/
{
name: 'Json Parser'
}
If you don't have JEST. you can run
yarn install
and to run tests
jest --verbose