I want to change the name of fields in an array by Jolt. Please explain how it works with your answer.
Input:
{
"referenceName": "***",
"name": "***"
}
Desired output:
{
"ReferenceName": "***",
"ColumnName": "***"
}
CodePudding user response:
You can use this simple spec:
[
{
"operation": "shift",
"spec": {
"referenceName": "ReferenceName",
"name": "ColumnName"
}
}
]
Or you can have simpler:
[
{
"operation": "shift",
"spec": {
"r*": "R&(0,1)",
"n*": "ColumnN&(0,1)"
}
}
]
When you want to change some names in your JSON, You can use the shift
operation like the above spec:
r*
: match all keys that started with ther
likereferenceName
and*
match everything afterr
that equalseferenceName
. You can writeR&(0,1)
that&(0,1)
value is equal to first*
.n*
: match all keys that started with then
likename
and*
match everything aftern
that is equal toame
. You can writeColumnN&(0,1)
that&(0,1)
value is equal to first*
.
Note: &
means the key's value, But when you use the &(0,1)
, you are saying that in the 0
level or current level please get the first *
value. Suppose you had a second *
in this level, You should get it like this: &(0,2)