Skip to content
cosmodev ~/tools/json-to-typescript

مبدل JSON به TypeScript

Converters & Formatters

هر JSON را بچسبانید و فوری interfaceهای TypeScript تمیز و تایپ‌دار بگیرید — primitiveها، اشیای تودرتو، آرایه‌ها و unionها، همه استنتاج‌شده. کلیدهای اختیاری، نقل‌قول واژه‌های رزروشده و حذف اشکال تکراری برایتان انجام می‌شود. کاملاً در مرورگر شما اجرا می‌شود.

اجتماع عناصر آرایه
تهی‌پذیر → اختیاری

(مستندات به انگلیسی)

What it does

The JSON → TypeScript tool reads any valid JSON and infers clean, typed TypeScript interfaces from it - no hand-writing types ever again. It handles nested objects (each gets a named sub-interface), arrays (T[]), heterogeneous arrays (merged into unions or a true union, your choice), primitive values, and null. Identical nested shapes are deduplicated into one shared interface, and keys that collide with TypeScript reserved words are auto-quoted. Everything runs 100% in your browser, so it’s safe to paste real, sensitive payloads.

How to use it

  1. Paste your JSON into the JSON input box (or hit Sample for a demo).
  2. Optionally set a Root name (defaults to Root, sanitized to a valid identifier).
  3. Pick Union array elements: Merge (default - objects merge keys, distinct primitives union) or Union (emit a true union of distinct element types).
  4. Toggle Nullable → optional to mark properties whose type includes null as optional.
  5. The interfaces render live on the right, pinned while you scroll the input.
  6. Copy the TypeScript, Download it as types.ts, or Copy share link to reproduce the exact view.

Examples

Infer an interface from a nested object

Input:

{ "id": 7, "name": "CosmoDev", "tags": ["json", "ts"], "meta": { "version": 2 } }

Output:

interface Root {
  id: number;
  name: string;
  tags: string[];
  meta: RootMeta;
}

interface RootMeta {
  version: number;
}

Heterogeneous arrays merge into a union element

Input: { "xs": [1, "a"] } → property xs: (number | string)[].

Reserved-word keys are quoted

Input: { "class": "x", "default": 1 } → "class": string; "default": number;.

Good to know

  • Shareable: your input and options are encoded in the URL, so a link reproduces the exact output.
  • Private: all inference happens locally - safe for secrets and credentials.
  • Related tools: JSON Formatter, JSON Validator, Base64Base64An encoding representing binary data as 64 safe ASCII characters, so it survives transport through text-only channels. It encodes — it does not encrypt..
کد منبع14 زبان

100% سمت کاربر · داده‌های شما هرگز از مرورگرتان خارج نمی‌شود. به کارتان آمد؟ آن را با یک همکار به اشتراک بگذارید.