abjoe
8 years agoNew Contributor II
Replace a single key in a json object
Hi All,
I want to replace just one keyname with another name. For example:
initial input :
{
“Field1”: “bar”,
“Field2”: “bar”
}
desired output :
{
“NEWNAME”: “bar”,
“Field2”: “bar”
}
I checked the docs and saw that we can use $.mapKeys to play with the keys.
https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1439367/Object+Functions+and+Properties#ObjectFunctionsandProperties-mapKeys
But I was not successful in changing the key. Whenever i tried, it was appending to all the keys in the object.
$.mapKeys((value, key) => “NEWNAME” + key)
When i used the below syntax, its giving only one key as output.
$.mapKeys((value, key) => “NEWNAME” + key)
Please help me to change just the name of a single key in the object.
Thanks in Advance.