How to replce value in text file of json

Hello,

i have below json and saved as in text json file

{
“billableSeconds”: 10800,
“timeSpent”: “3h”,
“location”: {
“name”: “Default Location”,
“id”: 1
},
“attributes”: {
WorkLocation”: {
“workAttributeId”: 1,
“value”: “”,
“type”: “STATIC_LIST”,
“key”: “WorkLocation”,
“name”: “Work Location”
},
TypeofHour”: {
“workAttributeId”: 5,
“value”: “”,
“type”: “STATIC_LIST”,
“key”: “TypeofHour”,
“name”: "Type of Hour "
},
HourType”: {
“workAttributeId”: 2,
“value”: “”,
“type”: “STATIC_LIST”,
“key”: “HourType”,
“name”: “Hour Type”
}
},
“comment”: “abc”,
“tempoWorklogId”: 1597584,
“timeSpentSeconds”: 10800,
“issue”: {
“key”: “DC0045-97”,
“id”: 505083,
“versions”: ,
“issueStatus”: “In Progress”,
“reporterKey”: “123”,
“internalIssue”: false,
“components”: [
15700
],
“issueType”: “Service Request”,
“projectId”: 611,
“projectKey”: “DC0045”,
“iconUrl”: “/abc/pqr/”,
“summary”: “xyz”
},
“originId”: 111,
“worker”: “USER123”,
“updater”: “USER234”,
“started”: “2023-07-25 08:28:00.000”,
“dateCreated”: “2023-07-27 08:28:53.000”,
“dateUpdated”: “2023-08-09 10:40:00.000”,
“originTa
skId”: 505083
}

i need to replace “workAttributeId”: 1 to “workAttributeId”: 2
“workAttributeId”: 5 to “workAttributeId”: 6 and
“workAttributeId”: 2 to “workAttributeId”: 3

how can i achieve that
after that i need to call this using http request as body.- for this i have 1 question
above json is formatted / i have beutified using json formatter so while reading as text file and passing that varible into body should it work directly or i need to pass in double cots as body acccepts string format.

help me on same

Hi Mathkar,

Serialize the text as json object with Activities - Deserialize JSON.
It’s a lot easier to manipulate json like that.

When you have a JObject you could do something like an assign:
yourJsonObject("attributes")("workAttributeId") = that + 1
(My syntax is probably wrong here, but you will figure it out :wink: )

Afterwards you can print the object again as string or do whatever else you needed to do with it.

2 Likes

Hello @Mathkar_kunal

You can loop the jTokens (“workAttributeId”) in a For Each activity by using JSON filter expressions to grab the required tokens and modify them.

For each jobj_JsonObject.SelectTokens("..[?(@.workAttributeId)]")
Assign currentJToken("workAttributeId") = CInt(currentJToken("workAttributeId"))+1

Example attached:
Increment number in json.xaml (12.8 KB)
jsonfile.json (1.5 KB)

Regards
Soren

1 Like

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