Json Replace String

Hi i wanted to help on modification of the json string by programatically.

package main

import (
xj “github.com/basgys/goxml2json

type PostJsonData struct {
ReqHeader struct {
ChannelID string json:"Channel_ID"
ServiceID string json:"Service_ID"
RequestID string json:"Request_ID"
RequestDate string json:"Request_Date"
} json:"ReqHeader"
ReqBody struct {
XML string json:"XML"
} json:"ReqBody"

func parseGhPost(rw http.ResponseWriter, request *http.Request) {
decoder := json.NewDecoder(request.Body)

var t PostJsonData
err := decoder.Decode(&t)

if err != nil {
xml := strings.NewReader(t.ReqBody.XML)
json, err := xj.Convert(xml)
if err != nil {
	panic("That's embarrassing...")
t.ReqBody.XML = json.String()


func main() {
http.HandleFunc("/", parseGhPost)
http.ListenAndServe(":3000", nil)

The post json is
“ReqHeader”: {
“Channel_ID”: “IndianPCS”,
“Service_ID”: “1051”,
“Request_ID”: “233111111”,
“Request_Date”: “20190423”
“ReqBody”: {
“XML”: “REQCACReqAsstOfCargoCharges20190926661643719rudss001kndlpt001NIXY12019091271223521725092019319EX5392019GINRCFA894905911040FNEN1WH911823C9 AROMATIC SOLVENT C91396.000MTNN26092019100133”

I need to convert the XML string to Json and insert back to same place and finally i need the full json but am not able to get full json remaining i have done using the above code.

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