命令行使用

cat abc.json | json2go 即可实现Json到go struct的转换

包使用

package main

import (
	"fmt"

	"github.com/m-zajac/json2go"
)

func main() {
	input :=
		`{
	"project_id": 85,
	"selectJobs": [
		{
		"is_selected binding:": 0,
	    "job_id": 15,
        "job_name": "abc"
        },
        {
        "is_selected binding:": 1,
        "job_id": 16,
        "job_name": "edf"
        }
    ]
    }`

	parser := json2go.NewJSONParser("Project")
	parser.FeedBytes([]byte(input))
	res := parser.String()
	fmt.Println(res)
}

输出
type Project struct {
        ProjectID       int     `json:"project_id"`
        SelectJobs      []struct {
                IsSelectedbinding       int     `json:"is_selected binding:"`
                JobI                    *int    `json:"job_i,omitempty"`
                JobID                   *int    `json:"job_id,omitempty"`
                JobName                 string  `json:"job_name"`
        }       `json:"selectJobs"`
}

类似库还有 https://github.com/wk30/xj2go