Support Questions
Find answers, ask questions, and share your expertise

NiFi drop JSON object

Highlighted

NiFi drop JSON object

Rising Star

Hello,

I am trying to filter a JSON stream with NiFi. Simply my JSON scheme is something like this;

{
    "jsonarray":[
        {
            "attribute1":"AAA",
            "attribute2":"BBB",
            "attribute3":"CCC",
            "element1_1":[
                "xyz",
                "xyz1",
                ....
            ],
            "element1_2":[
                "abc",
                "abc1",
                ...
            ],
            "element1_3":[
                "123",
                "1234",
                ...
            ]
        },
        {
            "attribute1":"XXX",
            "attribute2":"YYY",
            "attribute3":"ZZZ",
            "element2_1":[
                "xyz5",
                "xyz6",
                ....
            ],
            "element2_2":[
                "abc5",
                "abc6",
                ...
            ],
            "element2_3":[
                "333",
                "334",
                ...
            ]
        },
        ...
        ...
}

For example I want to filter when object contains "attribute1":"XXX", I would have this as result;

{
            "attribute1":"XXX",
            "attribute2":"YYY",
            "attribute3":"ZZZ",
            "element2_1":[
                "xyz5",
                "xyz6",
                ....
            ],
            "element2_2":[
                "abc5",
                "abc6",
                ...
            ],
            "element2_3":[
                "333",
                "334",
                ...
            ]
        }
...


Is it possible?

1 REPLY 1

Re: NiFi drop JSON object

Expert Contributor

You can use EvaluateJsonPath to extract the value of attribute1: and RouteonAttribute to make filtering based decisions for your flow.

Here is an example of evaluateJsonPath https://community.hortonworks.com/articles/64069/converting-a-large-json-file-into-csv.html

Here is an example of RouteonAttribute : https://community.hortonworks.com/articles/83610/nifi-rest-api-flowfile-count-monitoring.html

Don't have an account?