Nested Response json with array values in golang

how can i remove a specific set of key value from a nested json from every response received from a third party api and pass it to my post api in json format.

Example third party response:

“Caller”: {
“CallerID”: “ABC”,
“CallerIP”: “XXX”
“Environment”: “DEV”,
“WorkflowName”: “Something”,
“WorkflowMethod”: “GET”,
“Result”: “Success”,
“Output”: {
“Body”: {
“queryResponse”: {
“response_code”: “SUCCESS”,
“response_message”: {},
“change_number”: “abcdef”,
“templateId”: “”,
“title”: “random”,
“primary_application_instance”: “random”,
“primary_application”: “random”,
“external_csi_id”: [
#text”: “000000000”
“primary_ci”: {},
“start_date”: “0000-00-00 00:00:00”,
“end_date”: “0000-00-00 00:00:00”,
“model”: “notsure”,
“category”: “something”,
“requestor”: “random”,
“requestorsoeid”: “random”,
“outage_start_date”: {},
“outage_end_date”: {},
“expiry_time”: “0000-00-00 00:00:00”,
“justification”: “random”,
“risk”: “Low”,
“expedited”: false,
“expedited_reason”: {},
“backout_plan_exemption”: {},
“backout_plan”: “none”,
“cob_category”: {},
“pre_test_exempt”: true,
“test_exempt_category”: “dummy”,
“test_plan”: “NO NEED”,
“approvals”: [
“assignment_group”: “null”,
“comments”: {},
“status”: “notsure”,
“approver”: “abc”,
“updated”: “0000-00-00 00:00:00”
“TimeStamp”: “0000-00-00 00:00:00”,
“Location”: null

From this i need below to be removed and rest of nested json response to be used.

"Caller": {
    "CallerID": "ABC",
    "CallerIP": "XXX"
"Environment": "DEV",
"WorkflowName": "Something",
"WorkflowMethod": "GET",
"Result": "Success",

"TimeStamp": "0000-00-00 00:00:00",
"Location": null

The most widely used and powerful tool to manipulate JSON is jq. You can use it as a standalone tool or you can use a Go implementation:

1 Like

You can remove this part by unmarshalling into a struct without corresponding unnecessary fields specified and then marshalling it back into json format.

Can you please share me a snippet as i am new to programming

Thanks a lot Jabbson.!! Will try this and post the outcome here

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