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
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login
4 REPLIES 4

avatar
Super Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login

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.