Created 08-31-2022 12:55 PM
Hey everyone,
I would like to add an attribute to a json file. The json file is a result of an api query with the Invoke HTTP procesor. As a next step I want to add an attribute to the json file to the existing fields
I expected this:
[ {
"_id" : "5d55246b9ac36012c14b5e7c",
"gtin" : "4009602235038",
"target.sku : "59218_5_champagner", <- added attribute value
"articleNumber" : "59218-376",
"styleGroupId" : "59218",
"colorGroupId" : "376",
"brand" : {
"_id" : "57f75950a56ab89d1973ee36"
},
Does anyone have any ideas?
Created 08-31-2022 02:17 PM
Hi ,
You can use JoltJsonTransform Processor for that. So lets assume we have the following input:
[
{
"_id": "5d55246b9ac36012c14b5e7c",
"gtin": "4009602235038",
"articleNumber": "59218-376",
"styleGroupId": "59218",
"colorGroupId": "376",
"brand": {
"_id": "57f75950a56ab89d1973ee36"
}
}
]
Add JoltTranformJson processor and set the Jolt Specification property to the following, notice this property allows you to use Expression Language therefore you can reference attributes in the flowfile:
[
{
"operation": "modify-default-beta", //for modify-overwrite-beta
"spec": {
"*": {
"target.sku": "${target.sku}"
}
}
}
]
This will produce the following Json:
[ {
"_id" : "5d55246b9ac36012c14b5e7c",
"gtin" : "4009602235038",
"articleNumber" : "59218-376",
"styleGroupId" : "59218",
"colorGroupId" : "376",
"brand" : {
"_id" : "57f75950a56ab89d1973ee36"
},
"target.sku" : "someValue"
} ]
If you find this helpful please accept solution.
Thanks
Created 08-31-2022 02:17 PM
Hi ,
You can use JoltJsonTransform Processor for that. So lets assume we have the following input:
[
{
"_id": "5d55246b9ac36012c14b5e7c",
"gtin": "4009602235038",
"articleNumber": "59218-376",
"styleGroupId": "59218",
"colorGroupId": "376",
"brand": {
"_id": "57f75950a56ab89d1973ee36"
}
}
]
Add JoltTranformJson processor and set the Jolt Specification property to the following, notice this property allows you to use Expression Language therefore you can reference attributes in the flowfile:
[
{
"operation": "modify-default-beta", //for modify-overwrite-beta
"spec": {
"*": {
"target.sku": "${target.sku}"
}
}
}
]
This will produce the following Json:
[ {
"_id" : "5d55246b9ac36012c14b5e7c",
"gtin" : "4009602235038",
"articleNumber" : "59218-376",
"styleGroupId" : "59218",
"colorGroupId" : "376",
"brand" : {
"_id" : "57f75950a56ab89d1973ee36"
},
"target.sku" : "someValue"
} ]
If you find this helpful please accept solution.
Thanks
Created 09-04-2022 01:08 PM
Thanks Mr @SAMSAL for the insight. I learned from it because i was even thinking of telling him to use EvaluateJsonPath & ReplaceText processor.