Parses JSON while eagerly destringifying. A stringification tree is returned to allow the parsed/cleaned result to be edited and converted back to the original stringified format
$ yarn add json-destringify
$ npm install json-destringify
$ yarn build
$ yarn deploy
$ npm run build
$ npm run deploy
$ yarn test
$ npm run test
import { destringify, restringify } from 'json-destringify';
const sampleInput = JSON.stringify({ property: 'true' });
// sampleInput = "{\"property\":\"true\"}"
const { result, tree } = destringify(sampleInput);
// result = { property: true }
// tree = { count: 1, children: { property: { count: 1 } } }
const sampleOutput = restringify({ result, tree });
// sampleOutput = "{\"property\":\"true\"}"
const changedResult = {
property: false
};
const changedOutput = restringify({ result: changedResult, tree });
// changedOutput = "{\"property\":\"false\"}"
import { destringify, restringify } from 'json-destringify';
const input = {
property: [
JSON.stringify({
key: JSON.stringify(123)
})
]
};
/*
input = { property: [ '{"key":"123"}' ] }
*/
const destringified = destringify(input);
const restringified = restringify(destringified);
/*
restringified = { property: [ '{"key":"123"}' ] }
*/
const { result, tree } = destringified;
/*
result = { property: [ { key: 123 } ] }
tree = {
count: 0,
children: {
property: {
count: 0,
children: [
{
count: 1,
children: {
key: {
count: 1
}
}
}
]
}
}
}
*/