Simple transform JSON object structure. Rename JSON keys with ease.
First goal of this node module was to modify and maintain the structure of many translation files of angular-translate. Please note that the values of the input files never change, but the structural information.
npm install transform-json --save-dev
var transformJson = require('transform-json');
var input = {
a: 'some string'
};
var transform = {
'a': 'b' // renames 'a' to 'b'
};
var output = transformJson(input, transform);
console.log('output: ' + JSON.stringify(output)); // output: {"b":"some string"}
npm install -g transform-json
transform-json-cli --input=input.json --transform=transform.json --output=output.json
input.json:
{
"TRANSLATE_THIS": "My Translation",
"NAME": "My Name",
"SETTINGS": {
"SECTION_1": {
"MOO": "YES"
}
}
}
transform.json:
{
"NAME": ["SETTINGS.SECTION_2.MOO", "NAME"],
"TRANSLATE_THIS": "TRANSLATION"
}
output.json:
{
"TRANSLATION": "My Translation",
"NAME": "My Name",
"SETTINGS": {
"SECTION_1": {
"MOO": "YES"
},
"SECTION_2": {
"MOO": "My Name"
}
}
}
- Basically, a transform describes
{
"Let's rename this key": "into this key"
}
- You can also give an array as value
{
"Let's rename this key": ["into this key", "and this key"]
}
- You also can look into deep objects
{
"PARTS.PART1": "PARTS.PART2"
}
(This works also if you don't have a hierarchy but a key which is exactly "PARTS.PART1"
)
Copyright (c) 2015 Johannes Herrnegger. Licensed under the MIT license.