Hi All,

I have a JSON which looks as following:-

item[{
    "tags": ["Java","Hadoop","nimbus"]
    "id": "2233"
    "title": "testing with Java"
    "comments":[{"post_id":"2233","body":"try option1"} ,
{"post_id":"2233","body":"try option2"} , {"post_id":"2233","body":"try
option3"}]},

{
    "tags": ["Java","Hadoop"]
    "id": "2232"
    "title": "testing with Java"
    "comments":[{"post_id":"2232","body":"try option1"} ,
{"post_id":"2232","body":"try option2"} , {"post_id":"2232","body":"try
option3"},

{
    "tags": ["Java"]
    "id": "2231"
    "title": "testing with Java"
    "comments":[{"post_id":"2231","body":"try option1"} ,
{"post_id":"2231","body":"try option2"} , {"post_id":"2231","body":"try
option3"}
]

I need to convert the JSON to CSV.

Id                     Tags                                  Title              
                         
Body

2233  , <java><Hadoop><Nimbus>  ,   "testing with Java"   ,  <"try
option1"><"try option2"><"try option3">

2232  , <java><Hadoop>  ,   "testing with Java"   ,  <"try option1"><"try
option2"><"try option3">
.
.
I used a combination of EvaluateJSONPath and Replace Text for the same. 
First issue I'm facing is in parsing an array (Tags and Body). I couldn't
figure out how can iterate over the array of JSON values.

For Simplicity sake I configured EvaluateJSONPath with values shown in the
image:-

<http://apache-nifi-developer-list.39713.n7.nabble.com/file/n5776/EvaluateJsonPath.png>
 

and Replace Text processor with 
Regex expression as [\S\s]+ and Replacement Values as
"${Body}","${Tags},"${Post_id}","${Title}".

It works for single record.

Can you please provide pointer how to iterate through value of arrays.

Thanks,
Shweta








--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/How-to-iterate-through-complex-JSON-objects-tp5776.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.

Reply via email to