JSON to Go Struct

Paste JSON and get Go structs with json tags, where each nested object gets its own struct.

Add JSON and click Generate to see the code here.

How JSON to Go Struct works

Generates Go structs from a JSON sample. Each JSON object becomes a struct, and each field gets a json tag with the original key. Nested objects get their own struct, named after their key.

For an array of objects, all items are merged into one struct. Keys that only some items have become pointers with omitempty in the tag. Type the struct name you want in the Name box. Default is RootObject.

Input to JSON to Go Struct

  • Paste or type JSON into the input box, or upload a .json or .txt file. Then click Generate.
  • Use real sample data. Types are read from the values, so 42 gives int64, 4.2 gives float64 and "text" gives string.
  • Input must be valid JSON. If something is wrong, you see the line and column of the first error.

Output from JSON to Go Struct

  • Go structs with fields and tags lined up in columns.
  • Field names follow Go style, so user_id becomes UserID and api_url becomes APIURL.
  • Values that can be null become pointers like *string. Arrays become slices like []string, and null or mixed values become any.
  • There is no package line, so add your own. Copy it, download it as models.go or open it in full screen.