Home > Back-end >  Jolt converter keep key
Jolt converter keep key

Time:02-23

Let say I have an input

{
  "a": 1,
  "b": 2
}

with this spec

[
  {
    "operation": "shift",
    "spec": {
      "a": "wrapper.a",
      "b": "wrapper.b"
    }
  }
]

The output is

{
  "wrapper" : {
    "a" : 1,
    "b" : 2
  }
}

But i think maybe there is another shorter way to do the same thing, such as

[
  {
    "operation": "shift",
    "spec": {
      "*": "wrapper.[WHATEVER HERE, NEED HELP FROM YOU GUYS]"
    }
  }
]

Could you guys help to give the solution? Thanks

CodePudding user response:

You just can replace with the operators "*" to match key names of all attributes and "&" to substitute corresponding values for those attributes at the current level(within the current object) such as

[
  {
    "operation": "shift",
    "spec": {
      "*": "wrapper.&"
    }
  }
]

the demo on the site enter image description here

  • Related