Created on 03-15-2021 02:18 PM - edited 03-15-2021 02:19 PM
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
I would create a schema
then
PutDatabaseRecord
do you have an example of. the output data?
Created 03-15-2021 02:24 PM
Created 03-15-2021 02:46 PM
@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
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"
}
}
}
}
]