0x19 / gotostruct

Open source Go package designed to help you converting JSON objects into Go Structs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

License Build Status Go 1.3 Ready Go 1.4 Ready

GotoStruct

Open source Go package designed to help you converting JSON objects into Go Structs.

Examples

List of examples can be found within GotoStruct Examples.

Following code snippet:

package main

import (
	"fmt"
	gs "github.com/0x19/gotostruct"
	"strings"
)

func main() {
	gts := gs.GotoStruct{
		Name: "Example - Struct",
	}

	reader := strings.NewReader(`{"simple" : "json", "test": null, "something": [{"baz": 1}, {"baz": 2}]}`)

	response, err := gts.Generate(reader)

	if err != nil {
		fmt.Errorf("Got Error while generating struct: ", err)
	}

	fmt.Println(string(response))
}

will produce following struct:

type ExampleStruct struct {
	Simple    string `json:"simple"`
	Something []struct {
		Baz float64 `json:"baz"`
	} `json:"something"`
	Test interface{} `json:"test"`
}

Related Work

Parts of GotoStruct code are taken from Json-to-struct.

Contributing

I encourage you to contribute to GotoStruct! Please check out the Contributing to GotoStruct for guidelines about how to proceed.

About

Open source Go package designed to help you converting JSON objects into Go Structs.

License:MIT License


Languages

Language:Go 100.0%