Skip to content
/ xj2go Public
forked from cgxxv/xj2go

Convert xml and json to go struct

License

Notifications You must be signed in to change notification settings

yome/xj2go

 
 

Repository files navigation

xj2go

Go Report Card Build Status codecov codebeat badge

The goal is to convert xml or json file to go struct file.

Usage

Download and install it:

$ go get -u -v github.com/stackerzzq/xj2go

Import it in your code:

import "github.com/stackerzzq/xj2go"

Example

Please see the example file.

package main

import (
	"io/ioutil"
	"log"

	"github.com/stackerzzq/xj2go"
)

func main() {
	xmlfilename := "../testxml/xl/styles.xml"
	xj1 := xj2go.New(xmlfilename, "demoxml", "")
	xj1.XMLToGo()

	b1, err := ioutil.ReadFile(xmlfilename)
	if err != nil {
		log.Fatal(err)
	}

	if err := xj2go.XMLBytesToGo("test", "demoxml2", &b1); err != nil {
		log.Fatal(err)
	}

	jsonfilename := "../testjson/githubAPI.json"
	xj2 := xj2go.New(jsonfilename, "demojson", "sample")
	xj2.JSONToGo()

	b2, err := ioutil.ReadFile(jsonfilename)
	if err != nil {
		log.Fatal(err)
	}

	if err := xj2go.JSONBytesToGo("test", "demojson2", "github", &b2); err != nil {
		log.Fatal(err)
	}
}

About

Convert xml and json to go struct

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%