JSON 整理与类型生成可运行案例
权限清单:将接口响应整理为两空格缩进
格式化 权限清单 的合成响应,只改变 JSON 的书写空白,不补字段、不更改布尔值或数组顺序。priority 是示例规则排序值,不表示用户的安全级别。
试一试
在完整工具中打开 ↗示例工作台
JSON 整理与类型生成
pretty运行结果
{
"ok": true,
"data": {
"grants": [
{
"grantId": "demo-permissions-1",
"resource": "演示文档空间",
"priority": 1,
"granted": true,
"scope": "team",
"policy": {
"actions": [
"read"
],
"owner": "demo-team"
}
},
{
"grantId": "demo-permissions-2",
"resource": "演示项目仓库",
"priority": 2,
"granted": false,
"scope": "project",
"policy": {
"actions": [
"read",
"write"
],
"owner": "demo-project"
}
}
],
"summary": {
"total": 2,
"note": null
}
}
}原例已核验,可修改输入后重新运行。
⌘ / Ctrl + Enter 运行01
场景与操作说明
权限清单中的声明不能替代服务端授权判断。合成规则只帮助检查字段和差异,不会为账号授予权限。
priority 是示例规则排序值,不表示用户的安全级别。
- 核对 权限清单 的字段层级,保留 grantId 的字符串类型。
- 修改一项输入并运行,观察结果中的值或路径如何变化。
- 载入对照样本,复现下面的变化;恢复原例会替换当前输入。
02
对照样本
对照输入故意添加尾逗号,预期解析报错。格式化工具不自动猜测或修复不合法 JSON。
查看对照输入
{
"ok": true,
"data": {
"grants": [
{
"grantId": "demo-permissions-1",
"resource": "演示文档空间",
"priority": 1,
"granted": true,
"scope": "team",
"policy": {
"actions": [
"read"
],
"owner": "demo-team"
}
},
{
"grantId": "demo-permissions-2",
"resource": "演示项目仓库",
"priority": 2,
"granted": false,
"scope": "project",
"policy": {
"actions": [
"read",
"write"
],
"owner": "demo-project"
}
}
],
"summary": {
"total": 2,
"note": null
}
}
,}对照样本的实际结果
Expected double-quoted property name in JSON at position 697 (line 38 column 2)