Socket
Socket
Sign inDemoInstall

json-destringify

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    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


Version published
Maintainers
1
Install size
62.9 kB
Created

Readme

Source

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

FAQs

Last updated on 27 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc