Turn a JSON object, or an array of objects, into a TypeScript interface, a Python class, a Pydantic model or SQL. Pretty-printing stays on the JSON formatter
An API sample is often one JSON object, or a list of objects. This page writes a TypeScript interface, a Python class, a Pydantic model, or a CREATE TABLE and one INSERT per object. Formatting and repair stay on the JSON formatter.
{"id":1,"name":"Ada","ok":true,"tags":["a","b"],"meta":{"n":2}}, sets Mode to TypeScript interface, Name to Item, and leaves both checkboxes on. The result has export interface Item with id?: number, name?: string, ok?: boolean, tags?: string[] and meta?: ItemMeta, plus export interface ItemMeta with n?: number.item. The columns are id BIGINT NOT NULL, name TEXT NOT NULL, ok BOOLEAN NOT NULL, tags TEXT NOT NULL and meta TEXT NOT NULL. The INSERT is 1, 'Ada', 1, '["a","b"]', '{"n":2}'.from dataclasses import dataclass and from typing import Optional, List, then @dataclass class ItemMeta with n: Optional[int] = None, then @dataclass class Item with id, name, ok, tags: Optional[List[str]] = None and meta: Optional[ItemMeta] = None. Switch Mode to Pydantic model: the imports add from pydantic import BaseModel and both classes extend BaseModel, with no @dataclass. Show Example stays on TypeScript interface.The root must be one object, or an array of objects. A number, a string, or an array of numbers stops with an error. An object with no keys stops with an error.
TypeScript uses boolean, number and string. An array of one of those types becomes T[]. An empty array becomes unknown[]. A nested object becomes another interface: the parent name plus the key, so meta under Item is ItemMeta. Mixed types become unknown. Optional properties adds ? on every field. When the root is an array and a key is missing from some objects, that field is optional even if Optional properties is off. export writes export interface. An array root adds the comment // JSON root is Name[].
SQL lowercases Name and turns other characters into underscores, so Order Line becomes order_line. Integers are BIGINT, other numbers are DOUBLE, booleans are BOOLEAN and are written as 1 or 0, and strings are TEXT. A nested object or array is TEXT holding the JSON text. A single quote inside a string is doubled. A key that is null, or missing on any row, is nullable. Each object is one INSERT.
It is an object, so TypeScript names it ItemMeta. In SQL that same field is TEXT containing {"n":2}.
Each object becomes a row. A list of numbers has no columns.