Search code examples
jsonjolt

Convert String array to JSON object array using JOLT


Input :

[
  "link1",
  "link2"
]

Expected output:

[
  {
    "link": "link1"
  },
  {
    "link": "link2"
  }
]

I tried with multiple jolt spec without any luck. The closest one is:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "#link": "[&1].link"
      }
    }
  }
]

Solution

  • You can use @ wildcard as looping through the array while assigning the desired key(link) on the right hand side such as

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "@": "[&1].link"
          }
        }
      }
    ]
    

    the demo on the site https://jolt-demo.appspot.com/ is :

    enter image description here