Skip to content

Tool for generating Go type and variables from JSON file

License

Notifications You must be signed in to change notification settings

murooka/json2go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Oct 26, 2018
44277c2 · Oct 26, 2018

History

27 Commits
Oct 25, 2018
Aug 21, 2018
Oct 26, 2018
Aug 22, 2018
Oct 25, 2018
Oct 26, 2018
Oct 26, 2018
Oct 26, 2018
Oct 26, 2018

Repository files navigation

json2args

Example

Command

json2go --package main --typename Person --varname PersonList --output person.go persons.json

Input JSON File

[
    {
        "id": "3a98ee9c-6b60-4239-9d12-cbd637a904c9",
        "name": "alice",
        "age": 33
    },
    {
        "id": "cf17db3d-0cae-44c7-91a1-d834785a25e6",
        "name": "bob",
        "age": 19
    }
]

Output Go File

// Code generated by "json2go --package main --typename Person --varname PersonList --output person.go persons.json"; DO NOT EDIT.

package main

type Person struct {
	Age  int    `json:"age"`
	Id   string `json:"id"`
	Name string `json:"name"`
}

var PersonList = []Person{
	{
		Age:  33,
		Id:   "3a98ee9c-6b60-4239-9d12-cbd637a904c9",
		Name: "alice",
	},
	{
		Age:  19,
		Id:   "cf17db3d-0cae-44c7-91a1-d834785a25e6",
		Name: "bob",
	},
}

About

Tool for generating Go type and variables from JSON file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published