Skip to main content
MarioFRS
Gold ⭐️
August 31, 2022
Solved

how do Add attributes to a json file

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

MarioFRS_0-1661975374654.png

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?

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
August 31, 2022

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

 

 

 

 

 

 

 

2 replies

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
August 31, 2022

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

 

 

 

 

 

 

 

Translate
rafy
Gold ⭐️
September 4, 2022

Thanks Mr @SAMSAL for the insight. I learned from it because i was even thinking of telling him to use EvaluateJsonPath & ReplaceText processor. 

Translate