Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Add json object in the json content of flowfile

avatar
New Member

I have a json flowfile with below content

{

"name":"abc"

}

I want the output should be

{

"name":"abc",

"attributes":{

"id":"12233",

"map":"Y"

}

}


How to achieve the same?

1 ACCEPTED SOLUTION

avatar
Master Guru

You can use UpdateRecord for this, but make sure you have the additional fields in your writer's schema. Alternatively you can use JoltTransformJSON with the following spec:

[
  {
    "operation": "default",
    "spec": {
      "attributes": {
        "id": "12233",
        "map": "Y"
      }
    }
  }
]

View solution in original post

2 REPLIES 2

avatar
Master Guru

You can use UpdateRecord for this, but make sure you have the additional fields in your writer's schema. Alternatively you can use JoltTransformJSON with the following spec:

[
  {
    "operation": "default",
    "spec": {
      "attributes": {
        "id": "12233",
        "map": "Y"
      }
    }
  }
]

avatar
Explorer

@Matt Burgess do you mind helping me out with a similar issue?

I have a json file comming in as :

[ {
  "regId" : "us",
  "cId" : "SomeProduct",
  "weId" : 15,
  "name" : "R",
  "id" : 1539,
  "cityId" : 17,
  "cityName" : "Moskow"
}, {
  "regId" : "us",
  "cId" : "SomeProduct",
  "weId" : 15,
  "name" : "R",
  "id" : 1540,
  "cityId" : 18,
  "cityName" : "Berlin"
}, {
  "regId" : "us",
  "cId" : "SomeProduct",
  "weId" : 15,
  "name" : "R",
  "id" : 1541,
  "cityId" : 19,
  "cityName" : "Vienna"
} ]

I need to add 3 new fields passed from the FlowFile attribute into each element? Can I do that with the update Record also?

[ {
  "new_att":"somevalue",
  "new_att2":"somevalue2",
  "new_att3":"somevalue3",
  "regId" : "us",
  "cId" : "SomeProduct",
  "weId" : 15,
  "name" : "R",
  "id" : 1539,
  "cityId" : 17,
  "cityName" : "Moskow"
}, {
  "new_att":"somevalue",
  "new_att2":"somevalue2",
  "new_att3":"somevalue3",
  "regId" : "us",
  "cId" : "SomeProduct",
  "weId" : 15,
  "name" : "R",
  "id" : 1540,
  "cityId" : 18,
  "cityName" : "Berlin"
}, {
  "new_att":"somevalue",
  "new_att2":"somevalue2",
  "new_att3":"somevalue3",
  "regId" : "us",
  "cId" : "SomeProduct",
  "weId" : 15,
  "name" : "R",
  "id" : 1541,
  "cityId" : 19,
  "cityName" : "Vienna"
} ]

Thanks,

Rosa