Support Questions
Find answers, ask questions, and share your expertise

Apache Nifi add json array name

New Contributor

Hello everyone,

 

i need your help. I am relatively new to nifi and need your help. I am using the processor ConsumeKafkaRecord_2_6 1.15.3 with the record writer json set record writer. The output is then an array without object name. Which processor or setup can I use to add an array name to the json output? I get this Output 

 

[ {
  "moving_id" : 17078440,
  "store_id" : 9,
  "gtin" : 4064813288877,
  "qty" : -1.0,
  "condition_indicator" : 40,
  "issue_date" : 1656585240000,
  "received_date" : 1656547200000,
  "update_date" : 1656578057133
}, {
  "moving_id" : 17078441,
  "store_id" : 9,
  "gtin" : 4064813288907,
  "qty" : -1.0,
  "condition_indicator" : 40,
  "issue_date" : 1656585240000,
  "received_date" : 1656547200000,
  "update_date" : 1656578057133
} ]

 

and i need json file in this structur

 

{"stocks":
[ {
  "moving_id" : 17078440,
  "store_id" : 9,
  "gtin" : 4064813288877,
  "qty" : -1.0,
  "condition_indicator" : 40,
  "issue_date" : 1656585240000,
  "received_date" : 1656547200000,
  "update_date" : 1656578057133
}, {
  "moving_id" : 17078441,
  "store_id" : 9,
  "gtin" : 4064813288907,
  "qty" : -1.0,
  "condition_indicator" : 40,
  "issue_date" : 1656585240000,
  "received_date" : 1656547200000,
  "update_date" : 1656578057133
} ]}

 

 

1 ACCEPTED SOLUTION

Expert Contributor

Hi,

You can use the JoltTransformJson Processor and set the Jolt Specification value to :

 

[
 {
   "operation": "shift",
    "spec": {
           "*": "stocks[]"
           }
 }
]

 

Hope that helps. If it does, Please accept solution. Thanks

View solution in original post

4 REPLIES 4

Expert Contributor

Hi,

You can use the JoltTransformJson Processor and set the Jolt Specification value to :

 

[
 {
   "operation": "shift",
    "spec": {
           "*": "stocks[]"
           }
 }
]

 

Hope that helps. If it does, Please accept solution. Thanks

New Contributor

Thank you, this approach works well

Master Collaborator

@MarioFRS ,

 

What are you trying to do with the stock records after that step in your flow?

 

Cheers,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

New Contributor

@araujothe next step is with InvokeHTTP processor to update the stocks of products via Rest Endpoint

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.