Skip to main content
Emery
Gold ⭐️
January 21, 2025
Question

NiFi SplitJson, split json when expression condition is met and pass through when condition is not met

Hi, I've been trying to get this to work, but am not sure how to complete it.

From a previous SplitJson I have a queue of Flowfiles in these two formats.
{
"s_id": 1000,
"parent": 0,
"items": {
       "2020": {
                "s_id": 2020,
                 "parent": 1000
        },
        "2021": {
                "s_id": 2021,
                "parent": 1000
        }
  }
}
and
{
"s_id": 1001,
"parent": 0
}

I would like to un-nest them further to the Flowfiles.
{
"s_id": 1000,
"parent": 0
}

{
"s_id": 2020,
"parent": 1000
}

{
"s_id": 2021,
"parent": 1000
}

{
"s_id": 1001,
"parent": 0
}

I've tried another SplitJson with a JsonPath expression of $.items[*], however this throws a failure for the json where "items" doesn't exist.
Can someone please guide me on the steps and processors I should be using to complete this task?
Is it possible with some type of conditional statement in the SplitJson JsonPath expression?

Thank you for your help!

1 reply

Emery
EmeryAuthor
Gold ⭐️
January 22, 2025

Screenshot 2025-01-22 at 12.15.50 PM.png

To get the result I wanted this is the roundabout process I used. I would imagine there's a better way.

Translate