json-destringify

1.0.5 • Public • Published

json-destringify

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

Installation:

$ yarn add json-destringify
$ npm install json-destringify

Build:

$ yarn build
$ yarn deploy
$ npm run build
$ npm run deploy

Test:

$ yarn test
$ npm run test

Usage:

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\"}"

Example:

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
            }
          }
        }
      ]
    }
  }
}
*/

Readme

Keywords

none

Package Sidebar

Install

npm i json-destringify

Weekly Downloads

32

Version

1.0.5

License

MIT

Unpacked Size

64.4 kB

Total Files

15

Last publish

Collaborators

  • jharris4