Support Questions

Find answers, ask questions, and share your expertise

NiFi FlattenJSON is not working.

avatar
Super Collaborator

Hi,

Can anyone help me on how to use NiFi FlattenJSON processor.? i tried to send a JSON as input to the processor and it didnt change on the output. basically it output the same file..where as i was expecting it to flatten all the nested arrays,lists etc..

Regards,

Sai

1 ACCEPTED SOLUTION

avatar
@Saikrishna Tarapareddy

The FlattenJSON processor "flats out" any nesting in the JSON documents which are sent to it as inputs. Let me give you a quick example. So my JSON looks like this originally.

{
"Name":"A","age":"23",
"gender":"m",
"score":{
	"sub1":"56",
	"sub2":"66",
	"sub3":"76"
	}
}

Pay special attention to the column "score". It's a nested column! After passing it through FlattenJSON, it "flatten out" to something like this.

{
"Name":"A",
"age":"23",
"gender":"m",
"score.sub1":"56",
"score.sub2":"66",
"score.sub3":"76"
}

Now have a look at the format and "score" column(s) specifically! This is what FlattenJSON does.

Now since we have some level of understanding, do you have any nested column in your input which is not flattened?

PS - Arrays will remain as is after processing JSON data with FlattenJSON! So don't confuse arrays with nested columns.

View solution in original post

3 REPLIES 3

avatar
@Saikrishna Tarapareddy

The FlattenJSON processor "flats out" any nesting in the JSON documents which are sent to it as inputs. Let me give you a quick example. So my JSON looks like this originally.

{
"Name":"A","age":"23",
"gender":"m",
"score":{
	"sub1":"56",
	"sub2":"66",
	"sub3":"76"
	}
}

Pay special attention to the column "score". It's a nested column! After passing it through FlattenJSON, it "flatten out" to something like this.

{
"Name":"A",
"age":"23",
"gender":"m",
"score.sub1":"56",
"score.sub2":"66",
"score.sub3":"76"
}

Now have a look at the format and "score" column(s) specifically! This is what FlattenJSON does.

Now since we have some level of understanding, do you have any nested column in your input which is not flattened?

PS - Arrays will remain as is after processing JSON data with FlattenJSON! So don't confuse arrays with nested columns.

avatar
Super Collaborator

@Shu , @Rahul Soni

makes sense , my JSON is nested arrays so its not flattening it out..thank you.

Regards,

Sai

avatar
Master Guru

@Saikrishna Tarapareddy

Flatten json processor doesn't work if you are having arrays,nested arrays in the json content and the flowfile will route to failure if you are having array,nested arrays in the content. we still need to use splitjson (or) jolt transform processors to split the array.

As this processor joins all The keys are combined at each level with a user-defined separator that we have specified in the processor configs.

Input Json:-

{
    "id": 17,
    "name": "John",
    "child": {
        "id": "1"
    }}

Output json:-

{"id":17,"name":"John","child.id":"1"}

As you can see the nested json message has been joined with .(period) in the output json content.