https://github.com/basgys/goxml2json
XML to JSON converter written in Go (no schema, no structs)
https://github.com/basgys/goxml2json
converter go golang json xml
Last synced: 5 months ago
JSON representation
XML to JSON converter written in Go (no schema, no structs)
- Host: GitHub
- URL: https://github.com/basgys/goxml2json
- Owner: basgys
- License: mit
- Created: 2016-01-26T21:24:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T12:19:55.000Z (over 2 years ago)
- Last Synced: 2026-01-04T21:48:39.135Z (6 months ago)
- Topics: converter, go, golang, json, xml
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 291
- Watchers: 9
- Forks: 97
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goxml2json [](https://circleci.com/gh/basgys/goxml2json)
Go package that converts XML to JSON
### Install
go get -u github.com/basgys/goxml2json
### Importing
import github.com/basgys/goxml2json
### Usage
**Code example**
```go
package main
import (
"fmt"
"strings"
xj "github.com/basgys/goxml2json"
)
func main() {
// xml is an io.Reader
xml := strings.NewReader(`world`)
json, err := xj.Convert(xml)
if err != nil {
panic("That's embarrassing...")
}
fmt.Println(json.String())
// {"hello": "world"}
}
```
**Input**
```xml
bar
```
**Output**
```json
{
"osm": {
"-version": 0.6,
"-generator": "CGImap 0.0.2",
"bounds": {
"-minlat": "54.0889580",
"-minlon": "12.2487570",
"-maxlat": "54.0913900",
"-maxlon": "12.2524800"
},
"foo": "bar"
}
}
```
**With type conversion**
```go
package main
import (
"fmt"
"strings"
xj "github.com/basgys/goxml2json"
)
func main() {
// xml is an io.Reader
xml := strings.NewReader(`19.95`)
json, err := xj.Convert(xml, xj.WithTypeConverter(xj.Float))
if err != nil {
panic("That's embarrassing...")
}
fmt.Println(json.String())
// {"price": 19.95}
}
```
### Contributing
Feel free to contribute to this project if you want to fix/extend/improve it.
### Contributors
- [DirectX](https://github.com/directx)
- [powerslacker](https://github.com/powerslacker)
- [samuelhug](https://github.com/samuelhug)
### TODO
* Categorise errors
* Option to prettify the JSON output
* Benchmark