Go, Python and Java types from JSON
- Free
- No sign-up
- No upload
- Works offline
Tool facts
- Opens
JSON- Saves as
GOPYJAVA- Price
- Free, no sign-up, no watermark
- Are files uploaded?
- No. Everything is processed in this browser, on your device.
- Batch processing
- One file at a time
- Offline use
- Works without a connection once this page has loaded
- Browser
- A recent Chrome, Edge, Firefox or Safari, on computer or phone.
- Limits
- JSON nested more than 1000 levels deep is rejected.
Check it yourself: press F12, open the Network tab, then use the tool. No request carries your data.
About JSON to Go, Python and Java
JSON to Go, Python and Java reads a JSON sample and writes matching type declarations as you type: Go structs with json tags, Python dataclasses with from_dict and to_dict, Pydantic v2 models or TypedDicts, and Java classes or records with Jackson annotations. Field names follow each language's convention (content-type becomes ContentType, content_type or contentType) and the original key stays in the struct tag, the Pydantic alias, the dataclass converters or @JsonProperty, so the code reads and writes the same JSON.
Numbers are read from the source text, not through JSON.parse, so an ID such as 9007199254740993 is not rounded and is typed as int64, long or Python int; values past the 64-bit range become uint64, *big.Int or BigInteger. A number written with a decimal point or exponent is a float. When an array holds objects with different keys they are merged into one type and the keys that some objects lack become optional: omitempty with a pointer in Go, a None default in Python, NotRequired in a TypedDict and @JsonInclude(NON_NULL) in Java. The sample never leaves your browser.
JSON to Go, Python and Java runs entirely in your browser. Your data is processed on your device and is never uploaded to Qiyi or anyone else.
How to use JSON to Go, Python and Java
- Paste JSON into the JSON box, or open or drop a .json file. The sample shows a typical API response.
- Choose Go, Python or Java above the generated code.
- Set the Root type name, then the options for your language: pointers and omitempty for Go, dataclass, Pydantic v2 or TypedDict for Python, class or record for Java.
- Pick how integers are typed and whether field names are converted to the language's convention.
- Read the notes under the code, then press Copy or Download.
Frequently asked questions
Why is my ID typed as int64 even though it is small?
With Integers set to Auto every whole number becomes int64 in Go and long in Java, because IDs and counters tend to outgrow 32 bits after the sample was taken. Choose Smallest that fits to get int32 or int when every value in the sample fits in 32 bits. Python has a single int type, so this option does not change Python output. Numbers written as 1.0 or 1e3 are floats even though their value is whole.
What happens to integers larger than 2^53?
JavaScript's JSON.parse rounds them, so 9007199254740993 would become 9007199254740992. This page parses the text itself and keeps every digit. Values up to 2^63 - 1 become int64 or long, values up to 2^64 - 1 become uint64 in Go and BigInteger in Java, and anything larger becomes *big.Int or BigInteger. If a field mixes such integers with decimals, Go gets json.Number, Java BigDecimal and Python Union[int, float], so nothing is rounded on the way back out.
How are optional and null fields told apart?
A key that appears as null at least once is nullable: a pointer in Go, Optional without a default in Python, a boxed type in Java. A key that is missing from some objects of an array is optional: omitempty plus a pointer in Go, so that a present 0, empty string or false is still written, a default of None in Python and NON_NULL in Java. When one key is both missing and null in the sample, Go, Java and dataclasses cannot keep the difference and leave it out when writing; Pydantic and TypedDict keep it. The notes under the code list such keys.
Which versions do I need, and was the output tested?
Go 1.18 or newer (the code uses any), Python 3.10 for dataclasses and 3.11 for NotRequired in TypedDicts, Pydantic 2, and Jackson 2.12 or newer for records, which need Java 16. The generator was tested on 224 JSON documents with reserved words, invalid and Unicode keys: the Go code passes go vet and gofmt and round-trips through encoding/json, the Python code is validated in Pydantic strict mode, and the Java code compiles with javac and round-trips through Jackson's ObjectMapper.
Are there keys that cannot be mapped?
In Go, a struct tag can only hold letters, digits and some punctuation, so keys such as an empty string, an emoji, a comma or a quote cannot be tagged. Those fields get json:"-" and a comment, and encoding/json skips them. In Java the only such key is the empty string, because @JsonProperty("") means the default name; it is ignored with @JsonIgnoreProperties. Python keeps every key. Reserved words such as class, type or default get a trailing underscore or a Type suffix.