Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

JSON File Update

avatar
Explorer

Hi,

 

I have below JSON file with multiples image's details

{
    "images": [{
        "id": "C2934",
        "ds_folder_id": "759838458734"
    },
    {
        "id": "C8343",
        "folder_id": "3942879137986"
    }]
}.

 

I have id of the image and have to update the folder_id with some value.

 

For Example:

id is C8343 and the new folder_id is 2984584735

then I have to update folder_id of the JSON file with new one.

 

New JSON would be

{
    "images": [{
        "id": "C2934",
        "ds_folder_id": "759838458734"
    },
    {
        "id": "C8343",
        "folder_id": "2984584735"
    }]
}.

 

Please help me to perform above in NiFi.

1 ACCEPTED SOLUTION

avatar
Super Guru

@ravi_sh_DS The solution you are looking for is UpdateRecord.

 

Here is a great article with full info:

 

https://community.cloudera.com/t5/Community-Articles/Update-the-Contents-of-FlowFile-by-using-Update...

 

 

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  

 

Thanks,


Steven

View solution in original post

4 REPLIES 4

avatar
Super Guru

@ravi_sh_DS The solution you are looking for is UpdateRecord.

 

Here is a great article with full info:

 

https://community.cloudera.com/t5/Community-Articles/Update-the-Contents-of-FlowFile-by-using-Update...

 

 

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  

 

Thanks,


Steven

avatar
Explorer

thanks ! @stevenmatison for the detailed explanation.  🙂

avatar
Explorer

Hi @stevenmatison,

 

Thanks, but I have to make a judgemental update in JSON.  As I explained in the example only id with a particular value will be updated.

 

Please assist.

avatar
Super Guru

@ravi_sh_DS This gets a bit high level, so forgive me, as I am not sure how you know which ID to change and what to change it too.   That said, your approach could be to use QueryRecord and find the match you want, then update that match with UpdateRecord.  You can also split the json image array with SplitJson, then use UpdateRecord as suggested above.   In either method depending on your Use Case when you split the records and process the splits separately you may need to rejoin them downstream.

 

Some older methods useful here are SplitJson, EvaluateJson, UpdateAttribute, AttributeToJson, but the Query Update Records are now preferred as it is possible to do things more dynamically.