Socket
Socket
Sign inDemoInstall

clone-json

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clone-json

deep copy json


Version published
Maintainers
1
Created
Source

clone-json

Node Version Build Status Coverage Status Npm Downlaod

NPM

install

# Install with npm
$ npm install clone-json --save

# Install with yarn
$ yarn add clone-json

Usage

Two arrays are equal

let cloneJson = require('clone-json')

let json = {
  a: 123,
  b: 'str',
  c: true,
  d: [1, '2', false, {
    e: 3
  }],
  f: {
    g: 789,
    h: 'str',
    i: true,
    j: [2]
  }
}

let newJson = cloneJson(json)

newJson.a = 456
newJson.b = 'string',
newJson.c = false,
newJson.d[0] = 2
newJson.d[1] = '3'
newJson.d[2] = true
newJson.d[3].e = 4
newJson.f.g = 987
newJson.f.h = 'string'
newJson.f.i = false,
newJson.f.j[0] = 3

console.log(json) // => No changes have taken place
/* result: 
{
  a: 123,
  b: 'str',
  c: true,
  d: [1, '2', false, {
    e: 3
  }],
  f: {
    g: 789,
    h: 'str',
    i: true,
    j: [2]
  }
}
*/

console.log(newJson)
/* result:
{
  a: 456,
  b: 'string',
  c: false,
  d: [2, '3', true, {
    e: 4
  }],
  f: {
    g: 987,
    h: 'string',
    i: false,
    j: [3]
  }
}

Contributing

CommitsContributor
5Black-Hole

Author

Black-Hole

Keywords

FAQs

Package last updated on 17 May 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc