Online JSON to Go Struct| Support for nesting and multiple tags- GoTool Online Toolset

开发工具指南

This tool provides an online JSON-to-Go struct tool that can process multiple layers of nested JSON data. Supports automatic injection of multiple tags to ensure that the generated Go struct meets various requirements. The tool also has an error checking function, which can accurately mark error locations, help users quickly identify and repair problems, and improve the accuracy of data conversion and development efficiency.

使用说明

Feature Introduction

  1. Supports parsing nested JSON strings, recursively parsing nested objects.
  2. Supports parsing array JSON strings, parsing the first JSON string in the array.
  3. Supports injecting custom tags.
  4. Checks if the JSON string format is correct and outputs the error location.
  5. Supports line-by-line parsing of comments.

Example

Parsing Nested JSON String

{
    "name": "test", // Name
    "age": 10, // Age
    "addr": "Chengdu, Sichuan", // Address
    "cls_info": [ // Classes
        {
            "name": "Basketball Class", // Class Name
            "teacher": "Mr. Zhang" // Teacher
        },
        {
            "name": "Art Class", // Class Name
            "teacher": "Mr. Li" // Teacher
        }
    ]
}

After processing:

type ClsInfo struct {
    Name    string `json:"name"`    // Class Name
    Teacher string `json:"teacher"` // Teacher
}

type GenerateObj struct {
    Name    string    `json:"name"`    // Name
    Age     int       `json:"age"`     // Age
    Addr    string    `json:"addr"`    // Address
    ClsInfo []ClsInfo `json:"cls_info"` // Classes
}

Directly Parsing Array JSON String

[
    {
        "name": "test",
        "age": 10,
        "addr": "Chengdu, Sichuan",
        "cls_info": [
            {
                "name": "Basketball Class",
                "teacher": "Mr. Zhang"
            },
            {
                "name": "Art Class",
                "teacher": "Mr. Li"
            }
        ]
    },
    {
        "name": "test2",
        "age": 10,
        "addr": "Chengdu, Sichuan",
        "cls_info": [
            {
                "name": "Basketball Class",
                "teacher": "Mr. Zhang"
            },
            {
                "name": "Art Class",
                "teacher": "Mr. Li"
            }
        ]
    }
]

After processing:

type GenerateStruct struct {
    Name    string    `json:"name,omitempty"`
    Age     int       `json:"age,omitempty"`
    Addr    string    `json:"addr,omitempty"`
    ClsInfo []ClsInfo `json:"cls_info,omitempty"`
}

type ClsInfo struct {
    Name    string `json:"name,omitempty"`
    Teacher string `json:"teacher,omitempty"`
}