Reputation: 1
I have a JSON input that I am transform using JOLT shift. My problem is I want to use the value of an input key, as a new key in the output data, and in parallel add another value into that new outputted key. Here is my input:
"Description": {
"Name": "John",
"KeyNameId": "John123",
"Description": "John's description"
}
And I want my output to be:
"Description": {
"John123": "John's description"
}
Anyway to do this without using two shift operations? Or with two shifts if one isn't possible?
Upvotes: 0
Views: 2246
Reputation: 427
To be more precise,
[
{
"operation": "shift",
"spec": {
"Description": {
"@Description": "Description.@KeyNameId"
}
}
}
]
Upvotes: 0
Reputation: 4586
Yes, it can be done in a single shift using the "@(Number,words)" operator.
Input - slightly modified for clarity
{
"Top": {
"Name": "John",
"KeyNameId": "John123",
"Description": "John's description"
}
}
Spec
[
{
"operation": "shift",
"spec": {
"Top": {
// match the key "Description" and copy it's value to the Output.
// The Output path being defined by @(1,KeyNameId), which means
// go back up the tree 2 levels (0,1) and lookup the value of
// "KeyNameId"
"Description": "@(1,KeyNameId)"
}
}
}
]
Upvotes: 3