1

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 ?

1
  • I have tried below spec:[ { "operation": "shift", "spec": { "experence": { "*": { "year": "experence[&1].year", "corp": "experence[&1].corp" } } } } ] ,but it can not retrive higher level attribute called "name" Commented Mar 10, 2020 at 14:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it works and makes my topology running as expected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.