Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to order the output of a flowFile in NiFi

avatar

I have a flowile that has data in JSON format.

{

NAME: "xxx",

CITY: "yyy",

AGE:"00",

ZIPCODE: "12345",

ADDRESS: " "}

and I want to change the order so it can be displayed like this

{

NAME: "xxx",

AGE:"00",

ADDRESS: " ",

CITY: "yyy",

ZIPCODE: "12345",

}

Is this a processor that can do that

1 REPLY 1

avatar
Master Guru
@Sam LL

You can do this in NiFi by using Record oriented processors (ConvertRecord).

Using Convert Record processor:

input json:

{
NAME: "xxx",
CITY: "yyy",
AGE:"00",
ZIPCODE: "12345",
ADDRESS: " "}

Use ConvertRecord processor with Json Tree reader as controller service and give your matching avro schema and enable controller service.

Avro Schema:

{
"namespace": "nifi",
"name": "balances",
"type": "record",
"fields": [
{"name": "NAME", "type": ["null", "string"]},
{"name": "CITY", "type": ["null", "string"]},
{"name": "AGE", "type": ["null", "string"]},
{"name": "ZIPCODE", "type": ["null", "string"]},
{"name": "ADDRESS", "type": ["null", "string"]}
]
}

By using the configured reader convertRecord processor is able to read your incoming data.

To write in json format configure/enable JsonRecordSetWriter controller service and give the matching avro schema(change the order of the fields while writing)

AvroSchema:

{
"namespace": "nifi",
"name": "balances",
"type": "record",
"fields": [
{"name": "NAME", "type": ["null", "string"]},
{"name": "AGE", "type": ["null", "string"]},
{"name": "ADDRESS", "type": ["null", "string"]},
{"name": "CITY", "type": ["null", "string"]},
{"name": "ZIPCODE", "type": ["null", "string"]}
]
}

Now while writing the output data processor writes with the matching avro schema with ordering the fields in same way

Output:

[{"NAME":"xxx","AGE":"00","ADDRESS":" ","CITY":"yyy","ZIPCODE":"12345"}]

Refer to this link for configure/enabling ConvertRecord processor.

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer.


queryrecord.png