Search code examples
transformetlapache-nifijolt

NiFi Jolt transform list of string to Map


I would like to get convert list/array of string to dict/map using Jolt transform. Playground here: https://jolt-demo.appspot.com/#inception

Input json is:

{
  "sites": {
    "urls": [
      "https://google.com/",
      "https://www.netflix.com/",
      "https://www.epicgames.com/"
    ]
  }
}

Output expected:

{
  "sites": [
    {
      "link": {
        "url": "https://google.com/"
      }
    },
    {
      "link": {
        "url": "https://www.netflix.com/"
      }
    },
    {
      "link": {
        "url": "https://www.epicgames.com/"
      }
    }
  ]
}

I tried around other transforms but didn't found example for list of strings to map/dictionary. Here we have fixed key for output as link and url. Any pointer on solution will be helpful. Thank you.


Solution

  • Check this spec

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": {
              "*": {
                "@": "sites[].link.url"
              }
            }
          }
        }
      }
    ]