XML to JSON Converter for Go

Free online xml to json converter with Go code examples

Working with xml to json converter in Go? Our free online xml to json converter helps Go developers format, validate, and process data instantly. Below you will find Go code examples using encoding/xml / encoding/json (built-in) so you can achieve the same result programmatically in your own projects.

Try the XML to JSON Converter Online

Use our free XML to JSON directly in your browser — no setup required.

Open XML to JSON

Go Code Example

package main

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

type Root struct {
    XMLName xml.Name `xml:"root"`
    User    struct {
        Name string `xml:"name" json:"name"`
        Age  int    `xml:"age" json:"age"`
    } `xml:"user" json:"user"`
}

func main() {
    xmlData := `<root><user><name>Alice</name><age>30</age></user></root>`
    var root Root
    xml.Unmarshal([]byte(xmlData), &root)
    jsonBytes, _ := json.MarshalIndent(root, "", "  ")
    fmt.Println(string(jsonBytes))
}

Quick Setup

Library: encoding/xml / encoding/json (built-in)
// Built-in packages — no installation needed

Go Tips & Best Practices

  • Define structs with both xml and json tags
  • encoding/xml requires struct definitions for parsing
  • Use xml.Decoder for streaming large XML files

Frequently Asked Questions

XML to JSON Converter in Other Languages

More Go Tools