Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Add json object in the json content of flowfile

Solved Go to solution
Highlighted

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Add json object in the json content of flowfile

Super 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
Highlighted

Re: Add json object in the json content of flowfile

Super 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

Highlighted

Re: Add json object in the json content of flowfile

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



Don't have an account?
Coming from Hortonworks? Activate your account here