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.
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
- Phổ biếnKhả 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.
- Phổ biếnKhả 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ì.
- Phổ biếnKhả 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.
- Phổ biếnKhả 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ì.
- Phổ biếnKhả dụngCục bộ
Bộ Mã Hóa & Giải Mã URL
Mã hóa và giải mã URL, đổi query string sang JSON, đồng thời phân tích các thành phần URL.
- Phổ biếnKhả dụngCục bộ
Chuyển Đổi Unix Timestamp
Chuyển đổi dấu thời gian Unix (giây và mili-giây) sang ngày giờ 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 Tạo & Kiểm Tra Biểu Thức Cron
Tạo, kiểm tra và giải thích biểu thức cron 5 trường với lịch chạy tiếp theo.