Socket
Socket
Sign inDemoInstall

@glomex/cd-json-transformation

Package Overview
Dependencies
72
Maintainers
22
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @glomex/cd-json-transformation

## Example


Version published
Weekly downloads
1
decreased by-50%
Maintainers
22
Install size
3.93 MB
Created
Weekly downloads
 

Readme

Source

cd-json-transformation

Example

Let's say we have the following existing object we want to transform:

const origin = {
  id: 1,
  config: {
    flagA: true
  },
  values: {
    valueA: 'foo',
    valueB: 'bar'
  },
  arr: [0, 1, 2]
};

Now we want to do the following operations on this object:

  • Keep original structure
  • Remove values but copy values.valueA to value
  • Change config.flagA to false

First we use generateTemplate to get a template based on the original object:

  const { generateTemplate } = require('json-transformation');

  const template = generateTemplate(origin);

The result looks like this:

const template = {
  id: '{{id}}',
  config: {
    flagA: '{{config.flagA}}'
  },
  values: {
    valueA: '{{values.valueA}}',
    valueB: '{{values.valueB}}'
  },
  arr: [
    '{{arr.0}}',
    '{{arr.1}}',
    '{{arr.2}}'
  ]
};

Now we make the required changes:

const template = {
  id: '{{id}}',
  config: {
    flagA: false
  },
  value: '{{values.valueA}}',
  arr: [
    '{{arr.0}}',
    '{{arr.1}}',
    '{{arr.2}}'
  ]
};

…and use transform to create the new object:

  const { transform } = require('json-transformation');

  const newObj = transform(origin, template );

FAQs

Last updated on 08 Feb 2018

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