AE86
AE86

Reputation: 13

use jolt spec and convert json to json array

I have a question about transforming a json to jsonArray by jolt spec in apache nifi, my input is :

{
  "name": "tom",
  "experience ": [
    {
      "year": "2020",
      "corp": "aaaa"
    },
    {
      "year": "2019",
      "corp": "bbbb"
    }
  ]
}

and the output I need is :

[
  {
    "name": "tom",
    "year": "2020",
    "corp": "aaaa"
  },
  {
    "name": "tom",
    "year": "2019",
    "corp": "bbbb"
  }
]

can anyone help me ?

Upvotes: 1

Views: 309

Answers (1)

mattyb
mattyb

Reputation: 12093

This should work:

[
  {
    "operation": "shift",
    "spec": {
      "experience": {
        "*": {
          "@(2,name)": "[#2].name",
          "*": "[#2].&"
        }
      }
    }
  }
]

Note that you have a space in the field experience, I removed it from the spec (and the sample input) when testing on the online Jolt tester.

Upvotes: 1

Related Questions