Search code examples
jsonapache-nifijolt

Wrap JSON with square brackets using JOLT


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.


Solution

  • 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 http://jolt-demo.appspot.com/ is

    enter image description here