สร้าง TypeScript interfaces จากตัวอย่าง JSON พร้อม nested types, arrays และ optional fields ทำงานในเบราว์เซอร์ของคุณ
วิธีใช้ JSON เป็น TS
วาง JSON object หรือ array
ตั้งชื่อ root interface ตามต้องการ
คัดลอก TypeScript interfaces ที่สร้าง
This is a JSON to TypeScript generator that infers a set of interfaces from an example JSON object or array, so you can paste an API response and get ready-to-use types instead of writing them by hand.
It is a big time-saver when you are consuming an API or a config file: paste a response, optionally name the root interface, and copy clean TypeScript straight into your code.
Generation runs entirely in your browser, so your data never leaves your device, which matters when the sample contains real values.
It handles real-world shapes: nested objects become their own named interfaces referenced from the parent, arrays of objects are merged into one interface, and union types are produced where values vary.
When the objects in an array do not all have the same keys, the keys missing from some elements are marked optional with a question mark, which matches how the data actually behaves and keeps the types honest.
One important point: it infers a shape from the single sample you give it, rather than enforcing a schema. If a field is sometimes null or absent in real data but not in your sample, the generated type will not know that, so use a representative example.
คำถามที่พบบ่อย
แต่ละ nested object กลายเป็น named interface ของตัวเอง อ้างอิงจาก parent ดังนั้นผลลัพธ์สะอาดและนำกลับมาใช้ได้
Arrays ของ objects ถูกรวมเป็น interface เดียว และ keys ที่ขาดหายจากบางส่วนถูกทำเครื่องหมาย optional Arrays ของ primitives ที่ผสมกลายเป็น union element type
ไม่ types ถูกสร้างทั้งหมดในเบราว์เซอร์ของคุณ ดังนั้นข้อมูลของคุณไม่ออกจากอุปกรณ์
ฝังเครื่องมือนี้
เพิ่มเครื่องมือนี้ลงในเว็บไซต์ของคุณเอง คัดลอกสคริปต์ด้านล่าง โดยจะอัปเดตให้เป็นปัจจุบันโดยอัตโนมัติ
<iframe src="https://monu.tools/embed/th/json-to-typescript" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>เครื่องมือที่เกี่ยวข้อง
จัดรูปแบบ ทำให้สวยงาม และตรวจสอบ JSON ออนไลน์ พร้อมข้อความแสดงข้อผิดพลาดชัดเจนสำหรับข้อมูลที่ไม่ถูกต้อง
ย่อและตรวจสอบ JSON ในเบราว์เซอร์ของคุณ และดูว่าประหยัดได้กี่ไบต์
แปลง JSON เป็น CSV และ CSV กลับเป็น JSON ได้ทั้งสองทิศทาง เลือกตัวคั่น จัดการฟิลด์ที่มีเครื่องหมายอ้างอิง และคัดลอกผลลัพธ์ ทุกอย่างทำงานในเบราว์เซอร์ของคุณ
แปลง YAML เป็น JSON และ JSON กลับเป็น YAML ได้ทั้งสองทิศทาง ตรวจสอบความถูกต้องขณะแปลงและแสดงข้อผิดพลาดที่ชัดเจน ทุกอย่างทำงานในเบราว์เซอร์ของคุณ