I'm using github.com/basgys/goxml2json for xml to json conversion. Below is the example code:
package main
import (
"fmt"
"strings"
xj "github.com/basgys/goxml2json"
)
func main() {
xml := strings.NewReader(`<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
<bounds minlat="54.0889580" minlon="12.2487570" maxlat="54.0913900" maxlon="12.2524800"/>
<foo>bar</foo>
</osm>`)
json, err := xj.Convert(xml)
if err != nil {
panic("ERROR converting xml to json")
}
fmt.Println(json.String())
}
The output of the above code is:
{
"osm": {
"-version": 0.6,
"-generator": "CGImap 0.0.2",
"bounds": {
"-minlat": "54.0889580",
"-minlon": "12.2487570",
"-maxlat": "54.0913900",
"-maxlon": "12.2524800"
},
"foo": "bar"
}
}
However, I am expecting the output like below as given by https://codebeautify.org/xmltojson/y2221f265:
{
"osm": {
"bounds": "",
"foo": "bar"
}
}
How to remove the keys starting with -
from the JSON output? I do not know the structure of the data beforehand.