JSON 整理与类型生成可运行案例
订阅套餐:将接口响应整理为两空格缩进
格式化 订阅套餐 的合成响应,只改变 JSON 的书写空白,不补字段、不更改布尔值或数组顺序。priceCents 是示例价格字段,比较不同 interval 前应统一时间口径。
试一试
在完整工具中打开 ↗示例工作台
JSON 整理与类型生成
pretty运行结果
{
"ok": true,
"data": {
"plans": [
{
"planId": "demo-subscriptions-1",
"planName": "演示月度套餐",
"priceCents": 900,
"available": true,
"interval": "month",
"entitlements": {
"features": [
"export"
],
"seats": 1
}
},
{
"planId": "demo-subscriptions-2",
"planName": "演示年度套餐",
"priceCents": 9000,
"available": false,
"interval": "year",
"entitlements": {
"features": [
"export",
"team"
],
"seats": 5
}
}
],
"summary": {
"total": 2,
"note": null
}
}
}原例已核验,可修改输入后重新运行。
⌘ / Ctrl + Enter 运行01
场景与操作说明
套餐价格、计费周期和权益应一起核对。此页面不购买、续订或取消任何服务,全部为合成套餐。
priceCents 是示例价格字段,比较不同 interval 前应统一时间口径。
- 核对 订阅套餐 的字段层级,保留 planId 的字符串类型。
- 修改一项输入并运行,观察结果中的值或路径如何变化。
- 载入对照样本,复现下面的变化;恢复原例会替换当前输入。
02
对照样本
对照输入故意添加尾逗号,预期解析报错。格式化工具不自动猜测或修复不合法 JSON。
查看对照输入
{
"ok": true,
"data": {
"plans": [
{
"planId": "demo-subscriptions-1",
"planName": "演示月度套餐",
"priceCents": 900,
"available": true,
"interval": "month",
"entitlements": {
"features": [
"export"
],
"seats": 1
}
},
{
"planId": "demo-subscriptions-2",
"planName": "演示年度套餐",
"priceCents": 9000,
"available": false,
"interval": "year",
"entitlements": {
"features": [
"export",
"team"
],
"seats": 5
}
}
],
"summary": {
"total": 2,
"note": null
}
}
,}对照样本的实际结果
Expected double-quoted property name in JSON at position 709 (line 38 column 2)