Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@glomex/cd-json-transformation

Package Overview
Dependencies
Maintainers
22
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glomex/cd-json-transformation

## Example

latest
Source
npmnpm
Version
2.1.1
Version published
Maintainers
22
Created
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

Package last updated on 08 Feb 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