JSON to Go API
Generate Go struct types with json tags from a sample JSON document. Integers and floats are kept apart; arrays of objects are merged into one struct.
POST /api/v1/tools/json-to-goMCP json_to_goDeveloper ToolsGenerate Go structs with json tags from a JSON sample. Go style names like ID and URL, int64 or float64 numbers, omitempty, pointers and inline or named nested structs.
Input
Send these as a JSON object. Unknown fields are rejected.
- input
- A sample JSON document (object or array). (string, required)
- rootName
- Name of the top-level struct. (string, up to 100 characters, default "Root")
- omitEmpty
- Which fields get ,omitempty: none, optional (fields missing from some samples) or all. (string, one of none, optional, all, default "none")
- inline
- Nest object types as anonymous structs instead of separate named types. (boolean, default false)
- pointers
- Use pointer types (*T) for values that are null in the sample. (boolean, default false)
- anyType
- Spelling of the empty interface for unknown or mixed values. (string, one of any, interface{}, default "any")
curl https://pithlab.com/api/v1/tools/json-to-go \n -H "Authorization: Bearer $PITHLAB_KEY" \n -H "Content-Type: application/json" \n -d '{"input":"{\"id\":42,\"name\":\"Ada\",\"score\":9.5,\"tags\":[\"admin\"],\"address\":{\"city\":\"London\"}}","rootName":"User"}'Example response
{
"ok": true,
"result": {
"output": "type User struct {\n\tID int64 `json:\"id\"`\n\tName string `json:\"name\"`\n\tScore float64 `json:\"score\"`\n\tTags []string `json:\"tags\"`\n\tAddress Address `json:\"address\"`\n}\n\ntype Address struct {\n\tCity string `json:\"city\"`\n}\n"
}
}