bim/json-to-table
Composer 安装命令:
composer require bim/json-to-table
包简介
JSONPath implementation for querying and updating JSON objects with support for json flattening into a table
README 文档
README
This is a JSONPath implementation for PHP.
This implementation features all elements in the specification except the () operator (in the spcecification there is the $..a[(@.length-1)], but this can be achieved with $..a[-1] and the latter is simpler).
On top of this it implements some extended features:
- Regex match comparisons (p.e.
$.store.book[?(@.author =~ /.*Tolkien/)]) - For the child operator
[]there is no need to surround child names with quotes (p.e.$.[store][book, bicycle]) except if the name of the field is a non-valid javascript variable name. .lengthcan be used to get the length of a string, get the length of an array and to check if a node has children.
Features
This implementation has the following features:
- Convert json tree into a flat table using the set of jsonpath stings.
JsonPath Example
Consider the following json:
{ "store": {
"name":"My Store",
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95,
"available": true,
"authors": ["Nigel Rees"]
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99,
"available": false,
"authors": []
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99,
"available": true,
"authors": ["Nigel Rees"]
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99,
"available": false,
"authors": ["Evelyn Waugh", "J. R. R. Tolkien"]
}
],
"bicycle": {
"color": "red",
"price": 19.95,
"available": true,
"model": null,
"sku-number": "BCCLE-0001-RD"
},
"bicycleSet": [{
"color": "red",
"price": 19.95,
"available": true,
"model": null,
"sku-number": "BCCLE-0001-RD"
},{
"color": "green",
"price": 19.75,
"available": false,
"model": null,
"sku-number": "RCADF-0002-CQ"
}]
},
"authors": [
"Nigel Rees",
"Evelyn Waugh",
"Herman Melville",
"J. R. R. Tolkien"
],
"Bike models": [
1,
2,
3
]
}
JsonPath => Result
[$.store.bicycle.price]
| 19.95 |
[$.store.name,$.store.bicycle.price,$.store.bicycle.sku-number]
| My Store | 19.95 | BCCLE-0001-RD |
[$.store.book[*].price,$.store.book[*].price,$.store.book[*].authors[*],$.store.book[*].title,$.store.name]
| 8.95 | 8.95 | Nigel Rees | Sayings of the Century | My Store |
| 12.99 | 12.99 | null | Sword of Honour | My Store |
| 8.99 | 8.99 | Nigel Rees | Moby Dick | My Store |
| 22.99 | 22.99 | Evelyn Waugh | The Lord of the Rings | My Store |
| 22.99 | 22.99 | J. R. R. Tolkien | The Lord of the Rings | My Store |
Usage
$json = '{... your json as string ...}'; $jsonPath = '[$.your.jsonpath.1,$.your.jsonpath.2]'; $jsonObject = new JsonObject($json); $result = $jsonObject->getTable($jsonPath);
bim/json-to-table 适用场景与选型建议
bim/json-to-table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.17k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「path」 「jsonpath」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bim/json-to-table 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bim/json-to-table 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bim/json-to-table 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Declaratively specify how to extract elements from a JSON document
JSONPath implementation for querying and updating JSON objects
JSONPath implementation for querying and updating JSON objects
JSONPath implementation in PHP
Kinikit - PHP Application development framework MVC component
JSON storage, querying and modification.
统计信息
- 总下载量: 14.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2021-05-27