
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
json-transformer-cli
Advanced tools
Transform an object literal using JSONPath.
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.
JSONPath is like XPath for JavaScript objects. To learn the syntax, read the documentation for the JSONPath package on npm and the original article by Stefan Goessner.
json-transform /path/to/data.json /path/to/template.json /path/to/output.json
data.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]
}
}
}
template.json
{
"${environment}SomeJob": {
"When": "$$.JobA.Schedule",
"Command": "sh executeJob.sh $1 $2",
"Arguments": ["$$.JobA.Parameters.Parm1", "$$.JobA.Parameters.Parm2"],
"$$.JobA.QR": ""
}
}
output.json
{
"TEST_SomeJob": {
"When": {
"Months": [1,2,3,4,5,6,7,8,9,10,11,12],
"Days": [1],
"Method": "MONTHLY"
},
"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]
}
}
jsonPathObjectTransform(data, template);
Where data
and template
are both a plain Object
. Returns the transformed Object
.
Your template will be an object literal that outlines what the resulting object should look like. Each property will contain a JSONPath String
or Array
depending on how many properties from the source data you want to assign to the generated object.
{ destination: '$.path.to.source' }
Use a String
on your template property to assign a single object returned from your JSONPath. If your path returns multiple results then only the first is used.
var template = {
foo: '$.example'
};
var data = {
example: 'bar'
};
Result:
{
foo: 'bar'
}
FAQs
A CLI tool to transform an object literal using JSONPath.
The npm package json-transformer-cli receives a total of 4 weekly downloads. As such, json-transformer-cli popularity was classified as not popular.
We found that json-transformer-cli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.