Support Questions

Find answers, ask questions, and share your expertise

Specifying Datatype to JSON Key-Values while doing an Attribute To JSON conversion with NiFi

avatar
Super Collaborator

Hi All,

I am doing an attribute to json conversion using NiFi AttributesToJSON Processor. What is observed is that any key value pair is mapped to String datatype in the resultant JSON, which I believe is the intended behavior.

However, is there any known approaches to specify the datatype for a Key-Value pair? Currently I am employing an ExecuteScript processor once the JSON conversion is done to convert the "String" data type to whatever datatype I want the key-value to be in.

Are there other better approaches?

1 ACCEPTED SOLUTION

avatar
Master Guru

There is a JIRA to improve AttributesToJson to support types besides strings:

https://issues.apache.org/jira/browse/NIFI-2359

Currently all flow file attributes are stored as strings so there needs to be a way for the user to indicate the type for each attribute. For example, if attribute "foo" has a value of "true" we don't really know if the user wants true as a boolean or true as a string.

A convention could be created where each attribute could have a corresponding type attribute so something like:

attr1 = true

attr1.type = boolean

attr2 = true

attr2.type = string

View solution in original post

2 REPLIES 2

avatar
Master Guru

There is a JIRA to improve AttributesToJson to support types besides strings:

https://issues.apache.org/jira/browse/NIFI-2359

Currently all flow file attributes are stored as strings so there needs to be a way for the user to indicate the type for each attribute. For example, if attribute "foo" has a value of "true" we don't really know if the user wants true as a boolean or true as a string.

A convention could be created where each attribute could have a corresponding type attribute so something like:

attr1 = true

attr1.type = boolean

attr2 = true

attr2.type = string

avatar
Super Collaborator

@Bryan Bende : Thanks for pointing the Jira.