Stellar Sword
Stellar Sword

Reputation: 6216

Nifi output null values for EvaluateJson or AttributesToJson

So when I parse a file with EvaluateJSON the JSON looks like this:

{ "TEST_DATE": "", "T_DATE": "" }

When I do EvaluateJSON ($.TEST_DATE) to "test-date" on attributes... I get:

test-date: ""

Then when I do AttributesToJSON (flowfile-content destination) I get:

{ "test-date": "", "t-date": "" }

HOWEVER... I want it to be:

{ "test-date": null, "t-date": null }

I have tried every possible option. There is no way aside from "ReplaceText"-style dangerous regex to put NULL into the JSON.

Any updateAttribute fails to put "null" into it. I tried "replaceEmpty(null)", replaceEmpty("null") (which puts a string "null" instead). I tried "replaceEmpty(literal("null")) doesn't work.

It's like Nifi doesn't recognize null.

Upvotes: 2

Views: 4377

Answers (1)

Mahendran V M
Mahendran V M

Reputation: 3496

DExter,

You can replace the double quotes("") by null value in ReplaceText processor.

Afterwards you get below value.

{ "test-date": "", "t-date": "" }

Use ReplaceText processor to be search for empty double quotes and replace it with null.

search value:""
Replacement value:null

For your reference check this https://regexr.com/3kctp.

It will end like your required result;

{ "test-date": null, "t-date": null }

Please let me know, if you face any issues.

Upvotes: 3

Related Questions