Home > database >  get jolt json key,i hope transform key ,I have the following dataset that I need to transform:
get jolt json key,i hope transform key ,I have the following dataset that I need to transform:

Time:11-13

I don't know how to use jolt's transformations such as shiftdefaultmodify-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

the demo on the site enter image description here

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
      }
    }
  }
]
  • Related