JSON to Struct / Interface / Class

Paste JSON — get Go, TypeScript, Python & Java type definitions instantly

← Back to Conversion Tools
1
Paste JSON

Any JSON object or array

2
Set root name

Default: "Root"

3
Copy for your language

Go, TS, Python, or Java

Paste JSON and click Generate to see output

JSON Type Mapping — How Each Language Represents JSON Types

JSON TypeExampleGoTypeScriptPythonJava
string"hello"stringstringstrString
integer42intnumberintInteger
float3.14float64numberfloatDouble
booleantrueboolbooleanboolBoolean
nullnullinterface{}unknownAnyObject
array[1,2,3][]TT[]list[T]List<T>
object{"a":1}struct{...}interface{...}@dataclass classclass{...}

Why Generate Types from JSON?

API integration is the most common use case: you receive a JSON response from a REST or GraphQL API and need typed models in your language of choice. Manually writing struct definitions from a large JSON response is tedious and error-prone — a 100-line JSON object can take 30+ minutes to type out by hand, and a single mismatched field type causes runtime errors. Configuration files (package.json, terraform.tfstate, docker-compose.yml) are another frequent source: developers want type-safe access to config data. Code generation pipelines use JSON-to-type tools as a first step before generating serialization code, database schemas, or API documentation. This tool generates all 4 language outputs from a single JSON input — no signup, no API key, instant results.

Language-Specific Conventions

Go: Field names use PascalCase with json:"field_name" struct tags. String fields use string; numbers default to float64 unless clearly integers. Nested objects become nested struct types. The struct tag preserves the original JSON key for marshaling/unmarshaling.

TypeScript: Interfaces use PascalCase (e.g., Root, Address). Optional fields (from null values) get the ? modifier. Arrays use T[] syntax. Union types are generated for arrays with mixed element types.

Python: Uses @dataclass decorator with type hints. Fields get Optional[T] for nullable values. Nested objects become nested dataclass classes. Imports from dataclasses import dataclass and from typing import List, Optional are included.

Java: Generates POJO (Plain Old Java Object) classes with private fields, public getters/setters, and proper generic collections. Uses List<T> for arrays, Integer/Double/Boolean for nullable primitive wrappers.

Frequently Asked Questions

How do I convert JSON to a Go struct?

Paste your JSON, switch to the Go tab. The tool generates proper Go structs with json:"..." tags, nested struct types, and slice types for arrays. Fields use PascalCase with the original JSON key preserved in struct tags.

How do I generate TypeScript interfaces from JSON?

Select the TypeScript tab after pasting your JSON. Interfaces are generated with optional modifiers for nullable fields, array types using T[], and nested interfaces for nested objects.

Can this generate Python dataclass or Java class from JSON?

Yes — all 4 languages are generated simultaneously. Python: @dataclass with type hints and Optional/List from typing. Java: POJO with private fields, getters/setters, and generic collections. Switch tabs to see each language.

How does type inference work?

JSON values are mapped: strings → string/str/String, integers → int/number/int/Integer, floats → float64/number/float/Double, booleans → bool/boolean/bool/Boolean, null → interface{}/unknown/Any/Object, arrays → typed collections, objects → nested types. See the type mapping table above.

What about optional fields and null values?

Null JSON values generate optional/pointer types: *T or interface{} in Go, ? modifier in TypeScript, Optional[T] in Python, nullable wrappers in Java. Fields missing from some array elements are treated as optional across all outputs.