Xml to json. Conversion golang

Hi All,

I am working on a small modulw which takes a complex xml as input and formats it in a particular way in json… Not all the fields from the xml would come in the json and there are fields in the columns in different nodes which would be under one object in json… Is there an optimized way to do so.

In a very simple way you could use something like this

package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
)

type error struct {
	XMLName xml.Name `xml:"error"`
	Code    int      `json:"code",xml:"code"`
	Message string   `json:"message",xml:"message"`
}

func main() {
   	x := error{xml.Name{"", ""}, 200, "Error message"}
   	j, _ := json.Marshal(x)
    fmt.Printf("%v\n%v\n", x, string(j))
}

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