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.
TypeScript
Cách thức hoạt động
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ý.
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.
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.
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.
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
- Khả dụngCục bộ
Trình Tạo Mã UUID / GUID Ngẫu Nhiên (Phiên Bản 4)
Tạo mã định danh duy nhất toàn cầu UUID v4 có độ ngẫu nhiên mật mã cao hàng loạt.
- Khả dụngCục bộ
Trình Định Dạng, Xác Thực & Nén JSON / YAML / XML
Định dạng, làm đẹp, kiểm tra cú pháp và nén gọn chuỗi dữ liệu JSON, YAML và XML tức thì.
- Khả dụngCục bộ
Trình Tạo & Đọc Mã QR Tùy Chỉnh
Tạo mã QR tùy biến cho URL, văn bản, mật khẩu WiFi, danh thiếp vCard và quét mã QR.
- Khả dụngCục bộ
Bộ Mã Hóa & Giải Mã Base64
Chuyển đổi văn bản hoặc tệp sang chuỗi mã Base64 và giải mã ngược lại tức thì.
- Khả dụngCục bộ
Bộ Mã Hóa & Giải Mã URL
Mã hóa hoặc giải mã ký tự đặc biệt trong URL theo chuẩn percent-encoding (RFC 3986).
- Khả dụngCục bộ
Chuyển Đổi Dấu Thời Gian (Unix Timestamp)
Chuyển đổi Epoch Unix Timestamp sang ngày giờ thực tế và ngược lại.
- Khả dụngCục bộ
Chuyển Đổi Thực Thể HTML
Mã hóa và giải mã các ký tự đặc biệt HTML thành thực thể an toàn.
- Khả dụngCục bộ
Kiểm Tra Biểu Thức Chính Quy (Regex)
Thử nghiệm và gỡ lỗi biểu thức Regex với hiển thị so khớp thời gian thực.
- Khả dụngCục bộ
Giải Mã Token JWT
Giải mã phần Header, Payload và kiểm tra hạn sử dụng của JSON Web Token.
- Khả dụngCục bộ
Trình Hỗ Trợ Biểu Thức Cron
Tạo, giải thích và xem trước lịch chạy của biểu thức Cron biểu diễn thời gian.