InTab

JSON to Code

Generate TypeScript, C#, Java, Python, Go, Kotlin, Swift, Rust, PHP, Dart types from JSON.

Converters: Turn one format into another. It runs in your browser, so nothing you enter is uploaded.

What it does

JSON to Code generates typed models from a sample of JSON: interfaces and classes for TypeScript, C#, Java, Python, Go, Kotlin, Swift, Rust, PHP and Dart, or a JSON Schema. Nested objects become their own types and arrays become typed lists, so you can paste an API response and have models ready to use.

How to use it

  1. Paste JSON, or click Load sample.
  2. Choose the Language. Your choice is remembered.
  3. Set the Root type name, for example User or OrderResponse.
  4. Copy or download the generated code. It updates as you edit the JSON.

Example

{ "id": 7, "name": "Ada", "tags": ["math"], "address": { "city": "London", "zip_code": "EC1A" } }

TypeScript, with root type User:

export interface User {
  id: number;
  name: string;
  tags: string[];
  address: Address;
}

export interface Address {
  city: string;
  zip_code: string;
}

C# (System.Text.Json):

public class User
{
    [JsonPropertyName("id")]
    public long Id { get; set; }

    [JsonPropertyName("name")]
    public string Name { get; set; } = default!;

    [JsonPropertyName("tags")]
    public List<string> Tags { get; set; } = default!;

    [JsonPropertyName("address")]
    public Address Address { get; set; } = default!;
}

Good to know

  • Types are inferred from the sample. A field that is null in the sample cannot be typed, so give it a real value if you can.
  • When an array holds objects with different fields, fields missing from some items become optional.
  • Property names follow each language's convention (PascalCase in C#, snake_case in Python) and keep the original JSON name in an attribute or tag.
  • Escaped (stringified) JSON is unescaped first.

FAQ

Which C# serializer is used? System.Text.Json attributes (JsonPropertyName). The classes also work with Newtonsoft.Json if you change the attribute.

Can I generate classes from XML instead? Yes, with XML to Code.

Guides

More Converters tools