Home > Blockchain >  Wrap JSON with square brackets using JOLT
Wrap JSON with square brackets using JOLT

Time:08-19

I have this JSON

{
  "ID" : "fadfds2sdfs23",
  "JSON_TEXT" : {
    "ID" : "20220506000006073",
    "name" : "firstName lastName"
  },
  "STATUS" : "ACTIVE"
}

This is the output that I would like to have

[
  {
    "ID": "fadfds2sdfs23",
    "JSON_TEXT": {
      "ID": "20220506000006073",
      "name": "firstName lastName"
    },
    "STATUS": "ACTIVE"
  }
]

I'm trying to find resources about JOLT but rarely find the easy to grasp one. For removing the brackets is easier than this.

Please kindly help me (if possible please guide me to the spec too) Thank you very much.

CodePudding user response:

You can use just a single shift transformation such as

[
  {
    "operation": "shift",
    "spec": {
      "@": "[]"
    }
  }
]

where whole value represented by @ is wrapped up by square brackets []

the demo on the site enter image description here

CodePudding user response:

You can use two operation cardinality and shift for this

[
  {
    "operation": "shift",
    "spec": {
      "*": "objeto.&"
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "objeto": "MANY"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "objeto": ""
    }
  }
]
  • Related