1
0
mirror of https://github.com/halaxa/json-machine.git synced 2025-01-17 21:18:23 +01:00

Readme fixes

This commit is contained in:
Filip Halaxa 2018-12-02 20:27:16 +01:00
parent 9013c8fc02
commit 98c6e6d3cc

View File

@ -11,26 +11,19 @@ and uses native `json_decode` to decode JSON document chunks.
- Supports efficient iteration on any subtree of the document, specified by [Json Pointer](#json-pointer)
## TL;DR;
JSON Machine enables you to drop-in replace non efficient way of iterating big JSONs:
JSON Machine is drop-in replacement for non efficient:
```php
<?php
$users = json_decode(file_get_contents('500MB-users.json'));
- $users = json_decode(file_get_contents('500MB-users.json'));
+ $users = \JsonMachine\JsonMachine::fromFile('500MB-users.json');
foreach ($users as $id => $user) {
// the script will probably die before getting here
}
```
... by the efficient way:
```php
<?php
$users = \JsonMachine\JsonMachine::fromFile('500MB-users.json');
foreach ($users as $id => $user) {
// process $user with minimal memory footprint
}
```
Random access like `$users[42]` **is not possible**. However you can scan the collection in `foreach` and find the item.
## Parsing JSON documents
@ -109,10 +102,10 @@ Some examples:
| Json Pointer value | Will iterate through |
|--------------------|---------------------------------------------------------------------------------------------------|
| empty string | `["this", "array"]` or `{"a": "this", "b": "dictionary"}` will be iterated (main level - default) |
| (empty string) | `["this", "array"]` or `{"a": "this", "b": "dictionary"}` will be iterated (main level - default) |
| `/result/items` | `{"result":{"items":["this","array","will","be","iterated"]}}` |
| `/0/items` | `[{"items":["this","array","will","be","iterated"]}]` (supports array indexes) |
| `/` (gotcha!) | `{"":{"items":["this","array","will","be","iterated"]}}` (no kidding, see the spec) |
| `/` (gotcha! - a slash followed by an empty string) | `{"":["this","array","will","be","iterated"]}` |
## Parsing API responses