# @glomex/cd-json-transformation

> ## Example

Latest version **2.1.1** (published 2018-02-08) · Unlicensed license · 0 weekly downloads

## Install

```sh
npm install @glomex/cd-json-transformation
pnpm add @glomex/cd-json-transformation
yarn add @glomex/cd-json-transformation
bun add @glomex/cd-json-transformation
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2018-02-08 |
| First published | 2017-12-06 |
| Weekly downloads | 0 |
| License | Unlicensed |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 41.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Julian Hollmann |
| Maintainers | alexnick, bjurkowski, dacascas, defly, dimmy, dvselas, feriartos, glomex-all-the-things, hrb-d, idmitrieva, irynka, klipstein, krammi, marcelbeumer, maxbanton, mmatzanke, okinash, oleksandr.yefremov, olysyuk, pmdroid, r.kliuchko, tonkonozhenko |

## Links

- npm: https://www.npmjs.com/package/@glomex/cd-json-transformation
- Repository: https://github.com/glomex/cd-json-transformation
- Homepage: https://github.com/glomex/cd-json-transformation#readme
- Issues: https://github.com/glomex/cd-json-transformation/issues
- npm.io page: https://npm.io/package/@glomex/cd-json-transformation

## Dependencies (5)

- [traverse](https://npm.io/package/traverse.md) ^0.6.6
- [deep-equal](https://npm.io/package/deep-equal.md) ^1.0.1
- [object-path](https://npm.io/package/object-path.md) ^0.11.4
- [postinstall-build](https://npm.io/package/postinstall-build.md) ^5.0.1
- [@glomex/vvs-bump-version](https://npm.io/package/@glomex/vvs-bump-version.md) ^1.0.5

## Recent versions

- 2.1.1 (latest) — 2018-02-08
- 2.1.0 — 2018-01-25
- 2.0.2 — 2017-12-18
- 2.0.1 — 2017-12-18
- 2.0.0 — 2017-12-14
- 1.0.1 — 2017-12-07
- 1.0.0 — 2017-12-06

## README

# cd-json-transformation

## Example

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

```javascript
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:

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

  const template = generateTemplate(origin);
```

The result looks like this:

```javascript
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:

```javascript
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:

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

  const newObj = transform(origin, template );
```

---
_Source: https://npm.io/package/@glomex/cd-json-transformation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
