Skip to main content
sakina_shaikh
Bronze ⭐️⭐️⭐️
Apr 9, 2019 9:45 PM UTC
Solved

Add json object in the json content of flowfile

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?

mburgess
mburgessAnswer
Gold ⭐️⭐️⭐️
Apr 9, 2019 9:54 PM UTC

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"
      }
    }
  }
]

2 replies

mburgess
Gold ⭐️⭐️⭐️
mburgessAnswer
Gold ⭐️⭐️⭐️
Apr 9, 2019 9:54 PM UTC

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"
      }
    }
  }
]

Translate
rosa_negra
Silver ⭐️
Jun 4, 2019 12:09 AM UTC

@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



Translate