Skip to content

Commit dbd7108

Browse files
committed
Updated README
1 parent 26c838e commit dbd7108

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

README.md

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ This project aims to be a clean and simple implementation with the following goa
1919

2020
## Installation
2121

22-
**PHP 7.1+**
22+
**PHP >= 7.1+**
2323
```bash
2424
composer require softcreatr/jsonpath
2525
```
2626

2727
**PHP < 7.1**
2828

29-
Support for PHP < 7.1 has been dropped. However, legacy branches exist for PHP 5.6 and 7.0 and can be composer-installed as follows:
29+
1. Add to the `require`-section of your composer.json: `"softcreatr/jsonpath": "dev-oldphp"`
30+
2. Execute `composer install`
3031

31-
* PHP 7.0: `"softcreatr/jsonpath": "dev-php-70"`
32-
* PHP 5.6: `"softcreatr/jsonpath": "dev-php-56"`
33-
34-
🔻 Please note, that these legacy branches (based on JSONPath 0.6.2) are protected. There are no intentions to make any updates here. Please consider upgrading to PHP 7.1 or newer.
32+
🔻 Please note, that this legacy branch (based on JSONPath 0.7.2) is protected. There are no intentions to make any updates here. Please consider upgrading to PHP 7.1 or newer.
3533

3634
## JSONPath Examples
3735

@@ -69,6 +67,8 @@ Symbol | Description
6967

7068
## PHP Usage
7169

70+
#### Using arrays
71+
7272
```php
7373
use Flow\JSONPath\JSONPath;
7474

@@ -79,11 +79,37 @@ $data = ['people' => [
7979
['name' => 'Maximilian'],
8080
]];
8181

82-
print_r((new JSONPath($data))->find('$.people.*.name'), true);
83-
// $result[0] === 'Sascha'
84-
// $result[1] === 'Bianca'
85-
// $result[2] === 'Alexander'
86-
// $result[3] === 'Maximilian'
82+
print_r((new JSONPath($data))->find('$.people.*.name')->getData());
83+
84+
/*
85+
Array
86+
(
87+
[0] => Sascha
88+
[1] => Bianca
89+
[2] => Alexander
90+
[3] => Maximilian
91+
)
92+
*/
93+
```
94+
95+
#### Using objects
96+
97+
```php
98+
use Flow\JSONPath\JSONPath;
99+
100+
$data = json_decode('{"name":"Sascha Greuel","birthdate":"1987-12-16","city":"Gladbeck","country":"Germany"}', false);
101+
102+
print_r((new JSONPath($data))->find('$')->getData()[0]);
103+
104+
/*
105+
stdClass Object
106+
(
107+
[name] => Sascha Greuel
108+
[birthdate] => 1987-12-16
109+
[city] => Gladbeck
110+
[country] => Germany
111+
)
112+
*/
87113
```
88114

89115
More examples can be found in the [Wiki](https://github.com/SoftCreatR/JSONPath/wiki/Queries)
@@ -102,7 +128,7 @@ not very predictable as:
102128
```php
103129
use Flow\JSONPath\JSONPath;
104130

105-
$myObject = json_decode('{"name":"Sascha Greuel","birthdate":"1987-12-16","city":"Gladbeck","country":"Germany"}', false);
131+
$myObject = (new Foo())->get('bar');
106132
$jsonPath = new JSONPath($myObject, JSONPath::ALLOW_MAGIC);
107133
```
108134

0 commit comments

Comments
 (0)