Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
22
Weekly downloads
 
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

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