🍋
Menu
Web

JSON

JavaScript Object Notation

JSON (JavaScript Object Notation) คือรูปแบบข้อมูลน้ำหนักเบาที่ใช้สำหรับการแลกเปลี่ยนข้อมูล อ่านง่ายสำหรับทั้งมนุษย์และเครื่องจักร ใช้อย่างแพร่หลายใน Web APIs, ไฟล์การตั้งค่า และการจัดเก็บข้อมูลที่มีโครงสร้าง

รายละเอียดทางเทคนิค

JSON ถูกกำหนดใน RFC 8259 (ECMA-404) รองรับประเภทข้อมูล 6 ชนิด: string (UTF-8, escaped ด้วย ), number (IEEE 754), boolean (true/false), null, array ([...]) และ object ({"key": value}) ข้อจำกัด: ไม่รองรับ comments, trailing commas, undefined, dates (ใช้ string ISO 8601 แทน), หรือ circular references MIME type คือ application/json

ตัวอย่าง

```javascript
// JSON parse with reviver function
const data = JSON.parse(text, (key, val) => {
  if (key === 'date') return new Date(val);
  return val;
});

// JSON stringify with replacer and indentation
JSON.stringify(data, ['name', 'email'], 2);
```

รูปแบบที่เกี่ยวข้อง

เครื่องมือที่เกี่ยวข้อง

คำศัพท์ที่เกี่ยวข้อง