- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Converting Keys and values of a flat json to two separate columns in Nifi
- Labels:
-
Apache NiFi
Created on ‎03-15-2021 02:18 PM - edited ‎03-15-2021 02:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
After flattening a complex nested json to a flat json using the FlattenJson Processor, I want to load all the keys and values of that flat json to two separate columns of a table in database. What is the most efficient way to achieve this in Nifi?
Thanks in advance
@TimothySpann
@mburgess
@bbende
Created ‎03-15-2021 02:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would create a schema
then
PutDatabaseRecord
do you have an example of. the output data?
Created ‎03-15-2021 02:24 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Created ‎03-15-2021 02:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@TimothySpann As an example you can consider the below example json object,
{
"car1":"Ford",
"car2":"BMW",
"car3":"Fiat",
"car4":"Mercedes",
"car5":"Ferrari"
"car6":"Nissan"
}
Essentially, my table should be having 6 records in total. The values of first column should be car1, car2,........,car6 and the values of second columns should be Ford, BMW, Fiat, Mercedes, Ferrari, Nissan
Created ‎03-24-2021 03:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What are the column names in your table? Assuming "carId" and "carType", you can use JoltTransformJson or JoltTransformRecord with the following spec:
[
{
"operation": "shift",
"spec": {
"*": {
"$": "carId",
"@": "carType"
}
}
},
{
"operation": "shift",
"spec": {
"carId": {
"*": {
"@": "[&0].carId"
}
},
"carType": {
"*": {
"@": "[&0].carType"
}
}
}
}
]
