- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Nifi : Array of json elements to list of json elements
- Labels:
-
Apache NiFi
Created 12-17-2018 03:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a json input which structure is as follows:
[ { "line": [ { "element1": 4.908278133674332, "element2": 45.8293948360587 }, { "element1": 4.90838573779603, "element2": 45.82938855483125 } ], "coord": 1749, "xenius": "LYO01749", "label": "R M. BASTIE", "date": "2018-12-17" }, { "line": [ { "element1": 7.908278133674332, "element2": 8.8293948360587 }, { "element1": 4.555, "element2": 42.34534 } ], "coord": 223, "xenius": "LYO01749", "label": "R M. BASTIE", "date": "2018-12-17" } ]
And I would like to convert it into a list of json elements. Something like:
{ "line": [ { "element1": 4.908278133674332, "element2": 45.8293948360587 }, { "element1": 4.90838573779603, "element2": 45.82938855483125 } ], "coord": 1749, "xenius": "LYO01749", "label": "R M. BASTIE", "date": "2018-12-17" } { "line": [ { "element1": 7.908278133674332, "element2": 8.8293948360587 }, { "element1": 4.555, "element2": 42.34534 } ], "coord": 223, "xenius": "LYO01749", "label": "R M. BASTIE", "date": "2018-12-17" }
How could I do that with a json or jolt transformation, and not using SplitRecord?
Please note that I just want to get all the elements of the array and output them as a list of json elements, without the parent array.
Thanks in advance.
Created 12-17-2018 06:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use ConvertRecord for this, your JsonRecordSetWriter would have its Output Grouping property set to "One Line Per Object". The individual objects won't be pretty printed in the output as you have above, but it will remove the array braces as well as the comma delimiter, and just output each element of the above array as a JSON object on its own line.
Created 12-17-2018 06:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use ConvertRecord for this, your JsonRecordSetWriter would have its Output Grouping property set to "One Line Per Object". The individual objects won't be pretty printed in the output as you have above, but it will remove the array braces as well as the comma delimiter, and just output each element of the above array as a JSON object on its own line.
Created 12-18-2018 08:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Output Grouping... magical property 🙂
That did the trick. Thanks a lot Matt!
