Skip to content

Commit 745f20a

Browse files
author
Imani Manyara
committed
Initial release
0 parents  commit 745f20a

13 files changed

+1070
-0
lines changed

Diff for: CHANGELOG.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Changelog
2+
3+
All notable changes to `json-objects` will be documented in this file.
4+
5+
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
6+
7+
## v1.2.0 - 2021-01-14
8+
9+
### Added
10+
- Support for PHP 8.0
11+
12+
### Changed
13+
- Code style from PSR-2 to PSR-12
14+
- Migrated from Travis to GitHub actions
15+
16+
17+
## v1.1.2 - 2019-04-26
18+
19+
### Added
20+
- Support for PHP 7.1
21+
22+
23+
## v1.1.1 - 2019-04-26
24+
25+
### Fixed
26+
- Fixed streaming from PSR-7 classes by adding a custom stream wrapper
27+
28+
29+
## v1.1.0 - 2019-04-25
30+
31+
### Added
32+
- Support for PSR-7 messages and streams
33+
34+
35+
## v1.0.1 - 2019-03-26
36+
37+
### Changed
38+
- Use intermediate variable to check whether a source is valid
39+
40+
41+
## v1.0.0 - 2019-03-26
42+
43+
### Added
44+
- Released the first version of the package

Diff for: CODE_OF_CONDUCT.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to make participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at `[email protected]`. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

Diff for: CONTRIBUTING.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
We accept contributions via Pull Requests on [Github](https://github.com/cerbero/json-objects).
6+
7+
8+
## Pull Requests
9+
10+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``.
11+
12+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
13+
14+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
15+
16+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
17+
18+
- **Create feature branches** - Don't ask us to pull from your master branch.
19+
20+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
21+
22+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
23+
24+
25+
## Running Tests
26+
27+
``` bash
28+
$ composer test
29+
```
30+
31+
32+
**Happy coding**!

Diff for: LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2019 Andrea Marco Sartori <[email protected]>
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

Diff for: README.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# JSON Objects
2+
3+
[![Author][ico-author]][link-author]
4+
[![PHP Version][ico-php]][link-php]
5+
[![Build Status][ico-actions]][link-actions]
6+
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
7+
[![Quality Score][ico-code-quality]][link-code-quality]
8+
[![Latest Version][ico-version]][link-packagist]
9+
[![Software License][ico-license]](LICENSE.md)
10+
[![PSR-7][ico-psr7]][link-psr7]
11+
[![PSR-12][ico-psr12]][link-psr12]
12+
[![Total Downloads][ico-downloads]][link-downloads]
13+
14+
This package extracts JSON objects from large JSON sources like files, endpoints and streams while saving memory. It parses heavy JSONs by using [JsonStreamingParser][link-jsonstreamingparser] and provides an easy API to declare what objects to extract and process.
15+
16+
## Install
17+
18+
Via Composer
19+
20+
``` bash
21+
composer require cerbero/json-objects
22+
```
23+
24+
## Usage
25+
26+
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()`:
27+
28+
``` php
29+
$source = 'https://jsonplaceholder.typicode.com/users';
30+
31+
// Create a new instance specifying the JSON source to extract objects from
32+
new JsonObjects($source);
33+
// or
34+
JsonObjects::from($source);
35+
36+
// Create a new instance specifying the JSON source and the key to extract objects from
37+
new JsonObjects($source, 'address.geo');
38+
// or
39+
JsonObjects::from($source, 'address.geo');
40+
```
41+
42+
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`.
43+
44+
Under the hood `JsonObjects` supports PSR-7, hence any implementation of [MessageInterface][link-message-interface] or [StreamInterface][link-stream-interface] is a valid source. This makes interactions with other packages supporting PSR-7 (e.g. Guzzle) even more convenient:
45+
46+
``` php
47+
$response = $guzzle->get('https://jsonplaceholder.typicode.com/users');
48+
49+
// Create a new instance by passing an implementation of MessageInterface
50+
JsonObjects::from($response);
51+
52+
// Create a new instance by passing an implementation of StreamInterface
53+
JsonObjects::from($response->getBody());
54+
```
55+
56+
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:
57+
58+
``` php
59+
// Extract and process one object at a time from the given JSON source
60+
JsonObjects::from($source)->each(function (array $object) {
61+
// Process one object
62+
});
63+
64+
// Extract and process a chunk of objects at a time from the given JSON source
65+
JsonObjects::from($source)->chunk(100, function (array $objects) {
66+
// Process 100 objects
67+
});
68+
```
69+
70+
## Change log
71+
72+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
73+
74+
## Testing
75+
76+
``` bash
77+
$ composer test
78+
```
79+
80+
## Contributing
81+
82+
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.
83+
84+
## Security
85+
86+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
87+
88+
## Credits
89+
90+
- [Andrea Marco Sartori][link-author]
91+
- [JsonStreamingParser][link-jsonstreamingparser]
92+
93+
## License
94+
95+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
96+
97+
[ico-author]: https://img.shields.io/static/v1?label=author&message=cerbero90&color=50ABF1&logo=twitter&style=flat-square
98+
[ico-php]: https://img.shields.io/packagist/php-v/cerbero/json-objects?color=%234F5B93&logo=php&style=flat-square
99+
[ico-version]: https://img.shields.io/packagist/v/cerbero/json-objects.svg?label=version&style=flat-square
100+
[ico-actions]: https://img.shields.io/github/workflow/status/cerbero90/json-objects/build?style=flat-square&logo=github
101+
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
102+
[ico-psr7]: https://img.shields.io/static/v1?label=compliance&message=PSR-7&color=blue&style=flat-square
103+
[ico-psr12]: https://img.shields.io/static/v1?label=compliance&message=PSR-12&color=blue&style=flat-square
104+
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/cerbero90/json-objects.svg?style=flat-square&logo=scrutinizer
105+
[ico-code-quality]: https://img.shields.io/scrutinizer/g/cerbero90/json-objects.svg?style=flat-square&logo=scrutinizer
106+
[ico-downloads]: https://img.shields.io/packagist/dt/cerbero/json-objects.svg?style=flat-square
107+
108+
[link-author]: https://twitter.com/cerbero90
109+
[link-php]: https://www.php.net
110+
[link-packagist]: https://packagist.org/packages/cerbero/json-objects
111+
[link-actions]: https://github.com/cerbero90/json-objects/actions?query=workflow%3Abuild
112+
[link-psr7]: https://www.php-fig.org/psr/psr-7/
113+
[link-psr12]: https://www.php-fig.org/psr/psr-12/
114+
[link-scrutinizer]: https://scrutinizer-ci.com/g/cerbero90/json-objects/code-structure
115+
[link-code-quality]: https://scrutinizer-ci.com/g/cerbero90/json-objects
116+
[link-downloads]: https://packagist.org/packages/cerbero/json-objects
117+
[link-jsonstreamingparser]: https://github.com/salsify/jsonstreamingparser
118+
[link-message-interface]: https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php
119+
[link-stream-interface]: https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php
120+
[link-contributors]: ../../contributors

Diff for: composer.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "simtabi/json-objects",
3+
"type": "library",
4+
"description": "Extract objects from large JSON files, endpoints or streams while saving memory.",
5+
"keywords": [
6+
"cerbero",
7+
"json-objects",
8+
"json",
9+
"stream",
10+
"parser"
11+
],
12+
"homepage": "https://github.com/simtabi/json-objects",
13+
"license": "MIT",
14+
"authors": [{
15+
"name": "Simtabi",
16+
"email": "[email protected]",
17+
"homepage": "https://github.com/cerbero90",
18+
"role": "Developer"
19+
}],
20+
"require": {
21+
"php": ">=8.0",
22+
"psr/http-message": "^1.0",
23+
"salsify/json-streaming-parser": "^8.2"
24+
},
25+
"require-dev": {
26+
"mockery/mockery": "^1.3",
27+
"phpunit/phpunit": ">=7.0",
28+
"squizlabs/php_codesniffer": "^3.0"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"Cerbero\\JsonObjects\\": "src"
33+
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"Cerbero\\JsonObjects\\": "tests"
38+
}
39+
},
40+
"scripts": {
41+
"test": "phpunit",
42+
"check-style": "phpcs --standard=PSR12 src tests",
43+
"fix-style": "phpcbf --standard=PSR12 src tests"
44+
},
45+
"extra": {
46+
"branch-alias": {
47+
"dev-master": "1.0-dev"
48+
}
49+
},
50+
"config": {
51+
"sort-packages": true
52+
}
53+
}

0 commit comments

Comments
 (0)