[
{
"oldKey": "mykey",
"newKey": "myNewKey",
"values": [
{
"oldValue": 1,
"newValue": "Number 1"
},
{
"oldValue": 2,
"newValue": "Number 2"
}
]
}
]
But the values were only replaced, if there is a match in the 2nd element.
const mapping = require('json-mapping');
let json1 = {
"mykey": 1
};
let json2 = {
"mykey": 2
}
let mappingtable = [
{
oldKey: "mykey",
newKey: "myNewKey",
values: [ {"oldValue": 1, "newValue": "Number 1" },{ "oldValue": 2, "newValue": "Number 2" }]
}
];
let result1 = mapping.map(json1, mappingtable);
let result2 = mapping.map(json2, mappingtable);
console.log("result 1:");
console.log(result1);
console.log("result 2:");
console.log(result2);
result 1:
{}
result 2:
{ myNewKey: 'Number 2' }