TheDevTab
Tools

Search tools and guides

Ctrl K

Keyboard shortcuts

Ctrl K
Search tools and guides
?
Show keyboard shortcuts
Escape
Close menus and dialogs

JSON to Go

Generate tagged Go structs with optional-field controls for API samples.

Runs in your browser. Nothing is uploaded.

Infer Go structs from sample JSON

JSON to Go reads a JSON object or array and creates Go structs with exported PascalCase field names and json tags. Strings become string, whole numbers become int, decimal values become float64, booleans become bool, and empty or mixed values fall back to any. Nested objects become named structs, and arrays become slices. Paste a response, use the sample, or drop a JSON file to start.

JSON keys remain in the tags so a Go decoder can still read the original property names. When a field is missing from some objects in an array, its tag gains omitempty. When the sample includes null, the inferred field uses a pointer where a concrete type is available. These choices keep the output readable while making common optional and nullable cases visible for review.

Generated structs describe evidence

Inference cannot know whether a string is a timestamp, URL, account code, or enum. It cannot prove that a later API response has the same fields, either. Treat the output as a first draft. Rename structs to match the domain, add validation, decide whether a numeric field should really be an integer or decimal, and document fields that are nullable or optional. Go's type system can catch mistakes after unmarshalling, but the input still needs boundary checks.

Arrays of objects are merged by property name. A key present in every object is required unless All properties optional is enabled. A key present in only some examples gets omitempty. Mixed scalar types cannot be represented by one concrete Go field, so the generator uses any and leaves the final modeling decision to you. Add samples for success, empty, null, and error responses when an API has several shapes.

Fit the result into a Go project

The output is a set of declarations, not a complete package. It does not choose a JSON client, generate methods, add validation tags, or assume a web framework. The downloaded types.go file can be placed next to a fixture and edited with the package name and project conventions your codebase requires. Check field-name collisions when different JSON keys normalize to the same Go identifier.

Use JSON Formatter to check the source before conversion. The related JSON to TypeScript and JSON to Python pages use the same general sample-based inference idea for other codebases. If the source is YAML, format or validate it with YAML Formatter first, then make a deliberate conversion.

Local and private by design

JSON parsing, type inference, file reading, copying, and downloading all happen in your browser. TheDevTab does not send the sample to a server. Names of fields can reveal internal services even when values are removed, so use a sanitized example when sharing generated declarations. The output is a useful accelerator, but a human review remains the final step before committing it to a production repository.

FAQ

Does JSON to Go send my API example anywhere?

The JSON is parsed and passed to the Go inference engine in your browser, without a conversion service. The sample is never uploaded, and TheDevTab never receives it.

What does the generated Go code include?

The output uses exported PascalCase field names, json tags with the original keys, nested struct declarations, and slices for arrays. A custom Root name controls the root declaration name, while nested names are inferred from their field names.

How are optional fields handled?

For an array of object samples, a field missing from any object receives an omitempty JSON tag. The All properties optional option applies omitempty to every generated field.

How are null values represented?

A field that combines null with one concrete type uses a pointer such as *string, *int, or *bool. A null-only field or a field combining null with unrelated scalar types uses *any, while unrelated non-null scalar types fall back to any.

What happens when values have different scalar types?

Integer and floating-point observations can be widened to float64, while unrelated scalar types fall back to any. Review those fields against the real API contract before relying on the declarations.

Does the output include JSON validation code?

No. The result is a set of type declarations without decoding, validation, package names, or project-specific tags. Add those pieces in the Go codebase that will consume the JSON.