./prontouso.com
CÔNG CỤ LẬP TRÌNH

Tự Động Tạo Kiểu TypeScript từ JSON

Tạo các định nghĩa Interface hoặc Type trong TypeScript từ dữ liệu mẫu JSON, tự động phân tích các đối tượng lồng nhau và mảng dữ liệu.

Trạng thái công cụChạy trên trình duyệt của bạn
Xem trước

TypeScript

Cách thức hoạt động

  1. Nhập dữ liệu của bạn

    Điền các giá trị cần thiết, dán văn bản hoặc tải lên tệp bạn muốn xử lý.

  2. Xem kết quả tức thì

    Hầu hết các công cụ cập nhật theo thời gian thực khi bạn nhập liệu; một số công cụ sử dụng một nút hành động duy nhất.

  3. Sử dụng kết quả

    Sao chép, tải xuống hoặc chia sẻ kết quả được tạo — bạn luôn có toàn quyền kiểm soát dữ liệu của mình.

Quyền riêng tư & xử lý dữ liệuChạy cục bộ 100% trên trình duyệt của bạn. Công cụ này không tải dữ liệu của bạn lên máy chủ.

Tự Động Tạo Kiểu TypeScript từ JSON là gì?

Infer TypeScript interfaces or type aliases from a JSON sample so API responses and fixtures are easier to type.

TÌM HIỂU CÁCH HOẠT ĐỘNG CỦA CÔNG CỤ

How to generate TypeScript from JSON

How inference works

Objects become interfaces, arrays become arrays of inferred item types, primitive roots become type aliases, and nested object names are built from the root name plus the property path.

Arrays and mixed values

When array items have different shapes or primitive types, the output uses a union of the inferred item types. Empty arrays become unknown[] because there is no sample item to inspect.

Review before using

  • Rename interfaces if the generated names are too literal.
  • Mark fields optional manually when a sample omits some cases.
  • Replace null-only fields with a richer union if real data can contain other values.

Typing notes

Generated types describe the sample you pasted. Add optional fields, stricter unions, or shared interfaces when your real API contract is broader than the sample.

Các Câu Hỏi Thường Gặp (FAQ)

Does it know which fields are optional?

No. It only sees the provided sample, so every object property in that sample is generated as required.

What happens with invalid property names?

Properties that are not valid TypeScript identifiers are quoted, so keys like user-name remain usable.

Why did I get a type alias instead of an interface?

Primitive JSON roots such as a string, number, boolean, null, or array can be represented directly as a type alias.

Can it merge several response examples?

No. Paste a representative combined sample or adjust the generated types manually after comparing examples.

Công Cụ Liên Quan