cerbero/json-objects
Composer 安装命令:
composer require cerbero/json-objects
包简介
Extract objects from large JSON files, endpoints or streams while saving memory.
README 文档
README
This package extracts JSON objects from large JSON sources like files, endpoints and streams while saving memory. It parses heavy JSONs by using JsonStreamingParser and provides an easy API to declare what objects to extract and process.
Install
Via Composer
composer require cerbero/json-objects
Usage
Simply pass the JSON source (files, endpoints or streams) and optionally the key where objects are contained to create a new instance of JsonObjects. You can also call the factory method from():
$source = 'https://jsonplaceholder.typicode.com/users'; // Create a new instance specifying the JSON source to extract objects from new JsonObjects($source); // or JsonObjects::from($source); // Create a new instance specifying the JSON source and the key to extract objects from new JsonObjects($source, 'address.geo'); // or JsonObjects::from($source, 'address.geo');
When providing a key to extract objects from, you can use the dot notation to indicate nested sections of a JSON. For example nested.*.key extracts all the objects in the property key of every object contained in nested.
Under the hood JsonObjects supports PSR-7, hence any implementation of MessageInterface or StreamInterface is a valid source. This makes interactions with other packages supporting PSR-7 (e.g. Guzzle) even more convenient:
$response = $guzzle->get('https://jsonplaceholder.typicode.com/users'); // Create a new instance by passing an implementation of MessageInterface JsonObjects::from($response); // Create a new instance by passing an implementation of StreamInterface JsonObjects::from($response->getBody());
Finally you can decide whether to extract and process objects one by one or in chunks. The memory will be allocated to read only these objects instead of the whole JSON document:
// Extract and process one object at a time from the given JSON source JsonObjects::from($source)->each(function (array $object) { // Process one object }); // Extract and process a chunk of objects at a time from the given JSON source JsonObjects::from($source)->chunk(100, function (array $objects) { // Process 100 objects });
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
cerbero/json-objects 适用场景与选型建议
cerbero/json-objects 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29.93k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2019 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「stream」 「parser」 「cerbero」 「json-objects」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cerbero/json-objects 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cerbero/json-objects 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cerbero/json-objects 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Kinikit - PHP Application development framework MVC component
Object-Oriented API for PHP streams
Safely namespaced guzzle psr7 for WP2Static
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 29.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-25