I don't know how to use jolt's transformations such as shift
、default
、modify-default-beta
.
I have the following JSON value as
input :
{
"report": {
"q": "1",
"b": "2"
}
}
that I need to transform to
the desired output :
{
"report": {
"q": "1",
"b": "2"
},
"q": "1"
}
how can i handle it ?
Edit : I was actually trying to find a way to replicate,now i found :
[
{
"operation": "modify-default-beta",
"spec": {
"q": "@(2,report.&)"
}
}
]
CodePudding user response:
You can use a shift transformation spec like this
[
{
"operation": "shift",
"spec": {
"*": "&",
"@(0,report.q)": "q"
}
},
{
// this spec stands only for sorting to obtain the exact appearance with the desired result
"operation": "shift",
"spec": {
"report": "&",
"q": "&"
}
}
]
where zero in @(0,report.q)
represents the value taken from the current level
or another method would be by using shift transformation again :
[
{
"operation": "shift",
"spec": {
"*": {
"@": "&", // replicate the whole content
"q": "&" // replicate only attribute "q" without a node
}
}
}
]