Support Questions

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

Add json object in the json content of flowfile

avatar

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