Change values of a JSON key

Hi,

I have an API response JSON that i deserialize in order to retrieve values.

In this specific case I need to update a value in some cases and use the JSON in a put API.

I can retrieve values with .item.value or selectToken on my jObject, but how do i update a specific tokens value?

This is just a way to do that, But just give a try

After getting the values, make the entire JSON as a string and use string.Replace to replace that particular value @MarkusDS

Hi Hareesh, yes that could be a possible solution. I have a problem that the value i am replacing could exist more than once in the string, so thats why i would like to be able to do it by reference to the json key. That way the solution would be more robust. I could of course replace the key value as well to make it unique.

I will start out this way as a temporary solution,

Thanks for the solution tip,

After deserializing the values in the entire JSON, as you are getting the values like above, try assigning the value as

.item.value = “Text you want”

and give a try @MarkusDS

then again try printing the entire JSON.

Hi hareeshMR, that worked, thanks a lot. It is much easier to be able to pinpoint the exact value.

I have another problem though.

As you can see in this image, i need to update a value in one of these arrays. I know the code, but the array number can change. Sometimes it is 15 or 16 or something else. Can i make a lookup to find the array, that code “company name” is in?

@MarkusDS,

you don’t need to loop the JSON, but use a if condition and the string as you are using above,check the value as

item(“code”).Value = “company_name”

then, change the value. That will do the trick :slight_smile:

Hi hareesh,

i cant upload the json response, but it is attached below.

How can i get the item(“code”) if i dont make a loop with json-objects?

[
{
“boxes”: ,
“code”: “payment_reg_number”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646946,
“value”: “2640”
},
{
“boxes”: ,
“code”: “payment_swift_bic”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646956,
“value”: “NDEADKKK”
},
{
“boxes”: ,
“code”: “company_name”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646944,
“value”: “3D ANIMATION ApS”
},
{
“boxes”: ,
“code”: “voucher_type”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646941,
“value”: “invoice”
},
{
“boxes”: ,
“code”: “payment_date”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646957,
“value”: “2019-02-07”
},
{
“boxes”: ,
“code”: “total_amount_excl_vat”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646951,
“value”: “2887.5”
},
{
“boxes”: ,
“code”: “total_vat_amount_scanned”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646952,
“value”: “721.88”
},
{
“boxes”: ,
“code”: “invoice_date”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646943,
“value”: “2019-01-30”
},
{
“boxes”: ,
“code”: “payment_account_number”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646947,
“value”: “5903194857”
},
{
“boxes”: ,
“code”: “order_number”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646945,
“value”: “563”
},
{
“boxes”: ,
“code”: “catalog_creditor_id”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646931,
“value”: “DETTE ER EN TEST”
},
{
“boxes”: ,
“code”: “payment_iban”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646955,
“value”: “DK4920005903194857”
},
{
“boxes”: ,
“code”: “catalog_debitor_id”,
“data_type”: “”,
“error”: “”,
“value”: “”
},
{
“boxes”: ,
“code”: “total_amount_incl_vat”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646950,
“value”: “3609.38”
},
{
“boxes”: ,
“code”: “currency”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646948,
“value”: “DKK”
},
{
“boxes”: ,
“code”: “reference”,
“data_type”: “”,
“error”: “”,
“value”: “”
},
{
“boxes”: ,
“code”: “voucher_number”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646961,
“value”: “TEST”
},
{
“boxes”: ,
“code”: “joint_payment_id”,
“data_type”: “”,
“error”: “”,
“value”: “”
},
{
“boxes”: ,
“code”: “company_vat_reg_no”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646932,
“value”: “DK33747292”
},
{
“boxes”: ,
“code”: “purchase_order_number”,
“data_type”: “”,
“error”: “”,
“value”: “”
},
{
“boxes”: ,
“code”: “payment_code_id”,
“data_type”: “”,
“error”: “”,
“value”: “”
},
{
“boxes”: ,
“code”: “country”,
“data_type”: “”,
“error”: “”,
“feature_id”: 59646942,
“value”: “DK”
},
{
“boxes”: ,
“code”: “requisition_number”,
“data_type”: “”,
“error”: “”,
“value”: “”
},
{
“boxes”: ,
“code”: “payment_id”,
“data_type”: “”,
“error”: “”,
“value”: “”
}
]

As per the above screenshot, i thought you will have a child element name that is unique for all. But i don’t see any in the above JSON. So, you need to loop @MarkusDS :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.