Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

assign attribute/key to json array

assign attribute/key to json array

New Contributor

Hello,

 

I am new to nifi.

my flow is executeSQL with gave as result in avro and i converted into JSON. This is the JSON 

[
{
"jid": "testuser4@collabtest",
"participantseq": 23386
},
{
"jid": "testuser1@collabtest",
"participantseq": 23387
}
]

I want this as Output- Want to assign this array to participants attribute.

participants:[
{
"jid": "testuser4@collabtest",
"participantseq": 23386
},
{
"jid": "testuser1@collabtest",
"participantseq": 23387
}
]

Please help me Thank you

1 REPLY 1

Re: assign attribute/key to json array

Super Collaborator

You can change the contents of flow file as you suggest with ReplaceText.  

 

Change the Replacement Value to:

     "participants":$1

 

** added the ""s to make it respect the format.

 

This will change the contents adding the "participants" in front. 

 

 

If you are looking to create an actual attribute of the json values, then you need to use EvaluateJson processor.  Assuming the FlowFiles content is coming from replaceText above, with the participants array defined.  a new attribute added (+) to EvaluateJson Properties tab can access the array as:

 

$.participants

 

 

 

 

Don't have an account?
Coming from Hortonworks? Activate your account here