- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Apache Nifi add json array name
- Labels:
-
Apache NiFi
Created 07-05-2022 08:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
} ]}
Created 07-05-2022 09:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 07-05-2022 09:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 07-06-2022 01:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, this approach works well
Created 07-05-2022 03:30 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Created 07-06-2022 01:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@araujothe next step is with InvokeHTTP processor to update the stocks of products via Rest Endpoint
