JSON to Go
JSON to Go. Infers types from an example JSON document. Nested objects become named types by their key; mixed-type arrays fall back to a broad/any type. Runs on your device.
Runs on your device. The file is never uploaded.
JSON to Go turns one example document into struct declarations, tagging every field with json and the key exactly as your data spells it. Whole numbers become int64, fractional ones float64, and a null becomes interface{}. No package clause, no imports, no pointers and no omitempty, so an absent key decodes to the zero value.
Questions
What does it generate?
Go struct types, one per object in your example, each field carrying a json tag with the original key. The top-level struct is called Root and nested structs are named after the key holding them. Structs are printed with nested ones first, so the file compiles top to bottom.
Which Go types does it use?
A string becomes string, a boolean becomes bool, a whole number becomes int64 and a fractional one becomes float64. Arrays become slices of the element type taken from the first entry. A null becomes interface{}, and so does an empty array's element type.
How are field names derived?
The key has every non-alphanumeric character removed and its first letter capitalised, so user_name becomes Username and it is exported. The json tag keeps the original key exactly, so decoding still matches your data. Go initialisms such as ID and URL are not special-cased; rename them yourself if your linter asks.
Does it add a package line or imports?
No. The output is type declarations only, so paste it into a file that already has its package clause. Nothing here needs an import either, since every type used is builtin, including interface{} for nulls. Add your own encoding/json import in the file that marshals or unmarshals the structs.
Are there pointers or omitempty tags?
No. Every field is a value type and no tag options are added, so a key missing from the incoming JSON decodes to the zero value rather than to nil, and an empty field is still written out when you marshal. Add pointers or omitempty by hand where you need to tell absent from empty.
When does it refuse to run?
When the document has no object to build a struct from, which gives "top-level value has no object fields to name a type after", and when the input is not valid JSON, which reports the parser message. Documents nested more than 300 levels deep are refused as well.