Skip to content

Commit 470b788

Browse files
committed
docs: upgrade to the v2.0.8 version
Closes #24
1 parent c815fd9 commit 470b788

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

README.md

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ Get the contents of the JSON file:
9393

9494
```php
9595
/**
96-
* @param bool $associative If the returned object will be converted to an associative array.
96+
* @param bool $asObject If true and the value is an array, it is returned as an object.
9797
*
9898
* @throws GetFileException if the file could not be read.
9999
* @throws JsonErrorException if the file contains invalid JSON.
100100
*
101101
* @return mixed the contents of the JSON file.
102102
*/
103-
public function get(bool $associative = true): mixed;
103+
public function get(bool $asObject = false): mixed;
104104
```
105105

106106
Set the contents of a JSON or a key within the file:
@@ -292,7 +292,7 @@ use Josantonius\Json\Json;
292292

293293
$json = new Json('file.json');
294294

295-
$json->get(associative: false); // object(stdClass) { ["foo"] => string(3) "bar" }
295+
$json->get(asObject: true); // object(stdClass) { ["foo"] => string(3) "bar" }
296296
```
297297

298298
### Set an empty array in the JSON file contents
@@ -641,7 +641,7 @@ $json->shift('foo.bar.0'); // 1
641641
}
642642
```
643643

644-
### Remove a key and its value from the contents of a JSON file
644+
### Remove a string key and its value from the contents of a JSON file
645645

646646
**`file.json`**
647647

@@ -673,6 +673,68 @@ $json->unset('foo.bar');
673673
}
674674
```
675675

676+
### Remove a numeric key and its value from the contents of a JSON file
677+
678+
**`file.json`**
679+
680+
```json
681+
[
682+
1,
683+
2,
684+
3
685+
]
686+
```
687+
688+
**`index.php`**
689+
690+
```php
691+
use Josantonius\Json\Json;
692+
693+
$json = new Json('file.json');
694+
695+
$json->unset('1');
696+
```
697+
698+
**`file.json`**
699+
700+
```json
701+
{
702+
"0": 1,
703+
"2": 3
704+
}
705+
```
706+
707+
### Remove a numeric key and its value from the contents of a JSON file and re-index it
708+
709+
**`file.json`**
710+
711+
```json
712+
[
713+
1,
714+
2,
715+
3
716+
]
717+
```
718+
719+
**`index.php`**
720+
721+
```php
722+
use Josantonius\Json\Json;
723+
724+
$json = new Json('file.json');
725+
726+
$json->unset('1', reindexed: true);
727+
```
728+
729+
**`file.json`**
730+
731+
```json
732+
[
733+
1,
734+
3
735+
]
736+
```
737+
676738
### Add the provided data to the beginning of the contents of a JSON file
677739

678740
**`file.json`**

0 commit comments

Comments
 (0)