🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

json-transformer-cli

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-transformer-cli - npm Package Compare versions

Comparing version

to
1.0.6

2

package.json

@@ -33,3 +33,3 @@ {

},
"version": "1.0.5"
"version": "1.0.6"
}

@@ -6,3 +6,3 @@ # jsonpath-object-transform

Pulls data from an object literal using JSONPath and generate a new objects based on a template. Each of the template's properties can pull a single property from the source data or an array of all results found by its JSONPath. When pulling an array of data you can also supply a subtemplate to transform each item in the array.
Pulls data from an object literal using JSONPath and generate a new objects based on a template. Each of the template's properties can pull a single property from the source data. You can also apply the JSONPath to the key as well to append values from data into the key name. This version is specialized for CI/CD pipeline where json transformation via config file is part of some CI/CD process like Control-M Jobs as Code.

@@ -12,37 +12,54 @@ JSONPath is like XPath for JavaScript objects. To learn the syntax, read the documentation for the [JSONPath](https://www.npmjs.org/package/JSONPath) package on npm and the [original article](http://goessner.net/articles/JsonPath/) by Stefan Goessner.

## Usage
```js
var transform = require('jsonpath-object-transform');
```sh
json-transform /path/to/data.json /path/to/template.json /path/to/output.json
```
var template = {
foo: ['$.some.crazy', {
bar: '$.example'
}]
};
data.json
```json
{
"environment": "TEST",
"JobA": {
"Schedule": {
"Months": [1,2,3,4,5,6,7,8,9,10,11,12],
"Days": [1],
"Method": "MONTHLY"
},
"Parameters": {
"Parm1": "/some/path/to/jobfile.txt",
"Parm2": "/some/path/to/jobOutput.txt"
},
"QR": {
"RESOURCE_1": [1,50],
"RESOURCE_2": [2,25]
}
}
}
```
var data = {
some: {
crazy: [
{
example: 'A'
},
{
example: 'B'
}
]
template.json
```json
{
"${environment}SomeJob": {
"When": "$$.JobA.Schedule",
"Command": "sh executeJob.sh $1 $2",
"Arguments": ["$$.JobA.Parameters.Parm1", "$$.JobA.Parameters.Parm2"],
"$$.JobA.QR": ""
}
};
}
```
var result = transform(data, template);
```
Result:
```js
output.json
```json
{
foo: [
{
bar: 'A'
"TEST_SomeJob": {
"When": {
"Months": [1,2,3,4,5,6,7,8,9,10,11,12],
"Days": [1],
"Method": "MONTHLY"
},
{
bar: 'B'
}
]
"Command": "sh executeJob.sh $1 $2",
"Arguments": ["/some/path/to/jobfile.txt","/some/path/to/jobOutput.txt"],
"RESOURCE_1": [1,50],
"RESOURCE_2": [2,25]
}
}

@@ -82,66 +99,1 @@ ```

```
### Pulling an Array of Properties
```js
{ destination: ['$.path.to.sources'] }
```
Use an `Array` containing a single `String` to assign all results returned from your JSONPath.
#### Example
```js
var template = {
foo: ['$..example']
};
var data = {
a: {
example: 'bar'
},
b: {
example: 'baz'
}
};
```
Result:
```js
{
foo: ['bar', 'baz']
}
```
### Transform Items Returned in Array
```js
{ destination: ['$.path.to.sources', { item: '$.item.path' }] }
```
Use an `Array` with a `String` and an `Object` to assign all results returned from your JSONPath and transform each of the objects with a subtemplate.
#### Example
```js
var template = {
foo: [$..example, {
bar: '$.demo'
}]
};
var data = {
a: {
example: {
demo: 'baz'
}
},
b: {
example: {
demo: 'qux'
}
}
};
```
Result:
```js
{
foo: [
{ bar: 'baz' },
{ bar: 'qux' }
]
}
```