This is a common field flattener need for json->database tables. This example 
may help:
https://stackoverflow.com/questions/52926400/apache-nifi-1-7-1-flatten-json-with-delimiter

Thanks,

From: James McMahon <[email protected]>
Sent: Wednesday, March 9, 2022 2:47 PM
To: [email protected]
Subject: Transforming json

Hello. I am not that familiar with NiFi JSON processors, and am hoping someone 
can help me with a requirement to transform and parse incoming json. The 
biggest challenges for me here are that the keys in my incoming final_results 
can vary in number, and I need to use actual key names to form my json output 
results.

Here is a dummied up representation of an incoming object:
{
     "bigStructure":{
       .
       .
       .
          "final_results": {
               "Label1": {
                    "color": "red,
                    "temp": "0C"
                },
               "AnotherLabel": {
                    "color": "blue,
                    "temp": "32F"
                },
                 .
                 .
                 .
               "LastLabel": {
                    "color": "black,
                    "temp": "0K"
                }
          },
          "ID": "12345",
          "lastUpdated": "20220309"
       }
}

Here is what I need to generate as my output object:
{
     "Label1.color": "red",
     "Label1.temp": "0C",
     "AnotherLabel.color": "blue",
     "AnotherLabel.temp": "32F",
     "LastLabel.color": "black",
     "LastLabel.temp": "0K",
     "ID": "12345",
     "lastUpdated": "20220309"
}

I gather that this transformation needs to happen because they feed that output 
structure into a database that expects the data in this format.

Can I do this with "out of the box" nifi processors? Any help is much 
appreciated.
Thank you in advance!

Reply via email to