JSON 数据格式示例

这里收集了开发中常见的 JSON 结构。您可以直接复制这些代码到 JSON 格式化工具 中进行测试、验证或压缩。

1. 标准 API 响应 (RESTful)

{
  "code": 200,
  "message": "success",
  "timestamp": 1678892400,
  "data": {
    "user_id": 10086,
    "username": "developer_01",
    "roles": ["admin", "editor"],
    "profile": {
      "email": "dev@example.com",
      "verified": true
    }
  }
}

最常见的后端接口返回格式,包含状态码、消息和嵌套的数据对象。

2. 复杂嵌套数组 (电商商品列表)

{
  "total": 2,
  "page": 1,
  "limit": 20,
  "products": [
    {
      "id": 101,
      "name": "无线降噪耳机",
      "price": 199.99,
      "stock": 50,
      "tags": ["electronics", "audio", "wireless"],
      "specs": {
        "color": "black",
        "weight": "250g",
        "battery": "30h"
      }
    },
    {
      "id": 102,
      "name": "机械键盘",
      "price": 89.00,
      "stock": 0,
      "tags": ["electronics", "accessories"],
      "specs": {
        "switch": "cherry-red",
        "layout": "87-key"
      }
    }
  ]
}

3. 配置文件 (VS Code settings.json)

{
  "editor.fontSize": 14,
  "editor.tabSize": 2,
  "editor.formatOnSave": true,
  "files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/node_modules": true
  },
  "workbench.colorTheme": "One Dark Pro",
  "git.autofetch": true
}

为什么选择 JSON?

JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。它易于人阅读和编写,同时也易于机器解析和生成。 与 XML 相比,JSON 更小、更快、更易解析,因此成为现代 Web API 的标准数据格式。