- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to manipulate json key values using NiFI
- Labels:
-
Apache NiFi
Created ‎09-19-2018 05:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a json that comes from InvokeHTTP. I did a Split Json and JoltTransform to get the Key, Values, but I need to change all the Keys from Camelcase to snakecase. My Keys will be different with every InvokeHttp call. I've tried AttributestoJson and EvaluateJsonPath and some replace text, but haven't figured out a way to dynamically change just the keys and then merge back to the values without writing a custom processor.
Original Data from InvokeHTTP:
{ "data": { "Table": [ { "Age": 51, "FirstName": "Bob", "LastName": "Doe" }, { "Age": 26, "FirstName": "Ryan", "LastName": "Doe" } ] } }
Input after Split Json (Gives me each json in a separate flowfile) and Jolt:
[ { "Key": "Age", "Value": 51 }, { "Key": "FirstName", "Value": "Bob" }, { "Key": "LastName", "Value": "Doe" } ]
Desired Output:
{ "data": { "Table": [ { "age": 51, "first_name": "Bob", "last_name": "Doe" }, { "age": 26, "first_name": "Ryan", "last_name": "Doe" } ] } }
Created ‎09-19-2018 05:54 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you know the fields, you can use JoltTransformJSON on the original input JSON so you don't have to use SplitJson, here's a spec that will do the (explicit) field name conversion:
[ { "operation": "shift", "spec": { "data": { "Table": { "*": { "Age": "data.Table[#2].age", "FirstName": "data.Table[#2].first_name", "LastName": "data.Table[#2].last_name" } } } } } ]
You could also use UpdateRecord, you'd just need separate schemas for the JsonTreeReader and JsonRecordSetWriter.
