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

attributesToJSON returns attribute as string instead of json

Explorer

Output of attributesToJson is:

 

{"disconnectedNodeAcknowledged":"true","state":"STOPPED","revision":"{\"clientId\":\"f4b30e7b-016e-1000-7c5e-310be411ae67\",\"version\":9}"}

 

when it should be

 

{"disconnectedNodeAcknowledged":"true","state":"STOPPED","revision":{"clientId":"f4b30e7b-016e-1000-7c5e-310be411ae67","version":9}}

 

As you can see the revision property is encoded as string when it should be json.

How can I resolve this?

2 REPLIES 2

Master Guru

@lueenavarro 

 

NiFi stores all FlowFile attributes as strings.
And I am guessing you stored json in a FlowFile Attribute named revision.

 

The AttributestoJson processor builds a flat json from those attribute strings, so it is going to wrap the 

{"clientId":"f4b30e7b-016e-1000-7c5e-310be411ae67","version":9}

in quotes and escape the embedded quotes within that string with a backslash.

You could cleanup the produce json after it is built to remove the unwanted quotes and escape characters on the other quotes.  How you do this depends on whether your AttributesToJson processor is writing the output to a FlowFile Attribute or to the FlowFile's content.

If writing to a FlowFile's Attribute, you would use UpdateAttribute processor.
If writing to the FlowFile's content, you would use multiple ReplaceText processors.

 

Hope this helps,

Matt

 

 

Explorer

After attributestoJSON which wrote the attributes to file-content, I used replaceText and it worked. thanks for the help!

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.