Awesome Go

xj2go

CategoryText Processing
SubcategoryParsers/Encoders/Decoders
Stars0

Convert xml or json to go struct

About xj2go

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/wk30/xj2go/cmd/...

$ xj [-t json/xml] [-p sample] [-r result] sample.json

Import it in your code:

import "github.com/wk30/xj2go"

Example

Please see the example file.

package main

import (
	"io/ioutil"
	"log"

	"github.com/wk30/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)
	}
}

Frequently Asked Questions

What is xj2go?

xj2go is a Text Processing library for the Go programming language. Convert xml or json to go struct

How do I install xj2go?

Install xj2go with the Go module system using `go get stackerzzq/xj2go`. Check the repository for the current installation instructions.

What category does xj2go belong to?

xj2go is listed under Text Processing, specifically Parsers/Encoders/Decoders.

← Back to Parsers/Encoders/Decoders