JSON to Go, Rust, TypeScript: Code Generation Tools for Any Language
June 5, 2026 · 3 min read
One of the most repetitive tasks in backend development is translating a JSON API response into typed data structures for your language — Go structs, Rust structs, TypeScript interfaces, PHP arrays. You read the JSON, figure out the types, write the boilerplate, and repeat for every endpoint.
Code generation tools eliminate that step: paste a JSON sample, get ready-to-use type definitions instantly. Here is a tour of what is available on ZeroServer.Tools and when to use each.
JSON to TypeScript
TypeScript interfaces are the most commonly needed output. Given:
{
"id": 1,
"name": "Ada",
"active": true,
"score": 9.5,
"tags": ["developer", "writer"]
}
The JSON to TypeScript generator produces:
interface Root {
id: number;
name: string;
active: boolean;
score: number;
tags: string[];
}
Nested objects become separate interfaces and arrays are typed based on the first element. This is the right starting point for any TypeScript project that consumes a REST or GraphQL API — paste the actual response from your browser's Network tab and get the types in one click.
JSON to Go Struct
Go's encoding/json package requires exported struct fields with json:"" tags. Writing them by hand for a deep response object takes time. The JSON to Go Struct generator handles it automatically:
type Root struct {
Id int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Score float64 `json:"score"`
Tags []string `json:"tags"`
}
Field names are converted to PascalCase (required for Go exports), numbers map to int or float64 based on the sample, and nested objects become their own named structs.
JSON to Rust Struct
Rust's serde crate is the standard for JSON serialisation. Fields must be snake_case, but JSON keys are often camelCase — serde handles the rename automatically via #[serde(rename = "...")] attributes. The JSON to Rust Struct generator produces:
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub id: i64,
pub name: String,
pub active: bool,
pub score: f64,
pub tags: Vec<String>,
}
Add serde = { features = ["derive"] } and serde_json to your Cargo.toml and the generated code is ready to use. Nested objects become separate structs; arrays become Vec<T>.
JSON to PHP Array
PHP still powers a large share of the web. The JSON to PHP Array generator converts a JSON object into modern short-array syntax ([...]), with proper type mapping — JSON strings become PHP strings, booleans become true/false, and null maps to null.
[
'id' => 1,
'name' => 'Ada',
'active' => true,
'score' => 9.5,
'tags' => ['developer', 'writer'],
]
When the generator isn't enough
These tools derive types from a sample — which means:
- Optional fields look required if they always appear in your test data. Review generated types and add
?(TypeScript) orOption<T>(Rust) where fields can be absent. - Union types — e.g. a field that can be a string or a number — need manual adjustment; the generator picks the type of the first sample value.
- Large schemas with dozens of nested objects are still faster to start from a generator than from scratch, but expect to clean up naming and optionality.
The workflow that works best: generate the types from a real API response, then refine manually. The boilerplate is gone and you're editing, not writing from scratch.
Preparing the JSON first
Before generating types, it helps to have clean, formatted JSON. The JSON Formatter validates and pretty-prints your payload so you can see its structure clearly. If you are working with minified JSON from a network response, paste it there first, then copy the formatted version into the type generator.