Member-only story

Json Partial Update in Golang

Zhimin Wen
3 min readOct 4, 2023

--

Image by 422737 from Pixabay

I have a set of test profile as in Postman collections. I need to update the URL path to the new hostname and path. I export the Postman collections and get the following Json file (simplified for illustration purpose),

{
"info": {
"_postman_id": "c8f9633b-25ac-4c62-b6a7-6078f2a67246",
"name": "Reqres APIs",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "1297627"
},
"item": [
{
"name": "pages",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"page\": 2\n}"
},
"url": {
"raw": "https://reqres.in/api/users",
"protocol": "https",
"host": [
"reqres",
"in"
],
"path": [
"api",
"users"
]
}
},
"response": []
}
]
}

I need to update the URL to the new url to something as https://example.newhost.com/Sample/UAT/v1/api/users

Since we get a text based Json file, some shell techniques (such as sed) can help us to replace the raw URL field quickly.

But this is not enough, when import back to Postman, the URL field becomes all empty. The detail host, path fields need to be updated also.

--

--

No responses yet