Skip to content

Commit d38b2a8

Browse files
committed
Document PR #18
1 parent c79c4a4 commit d38b2a8

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ JSON for the XP Framework ChangeLog
77

88
**Heads up:** Dropped support for PHP < 7.4, see xp-framework/rfc#343
99
(@thekid)
10+
* Merged PR #18: Extend `Json::read()` and `Json::write()` to accept
11+
files and streams
12+
(@thekid)
1013
* Made serialization of integer keys consistent with `JSON.stringify()`
1114
(@thekid)
1215
* Merged PR #16: Return `{}` as empty object instead of empty array

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,43 @@ Reads and writes JSON to and from various input sources.
1212

1313
Examples
1414
--------
15-
Reading can be done from a string using one of the `Input` implementations:
15+
Reading can be done from a string, file or stream:
1616

1717
```php
18+
use text\json\Json;
19+
use io\File;
20+
use peer\SocketInputStream;
21+
1822
// Strings
1923
$value= Json::read('"Test"');
2024

2125
// Input
22-
$in= new FileInput(new File('input.json'));
23-
$in= new StringInput('{"Hello": "World"}');
24-
$in= new StreamInput(new SocketInputStream(...));
26+
$in= '{"Hello": "World"}');
27+
$in= new File('input.json');
28+
$in= new SocketInputStream(/* ... */);
2529

2630
$value= Json::read($in);
2731
```
2832

29-
Writing can be done to a string or using one of the `Output` implementations:
33+
Writing can be done to a string, file or stream:
3034

3135
```php
36+
use text\json\Json;
37+
use io\File;
38+
use peer\SocketOutputStream;
39+
3240
// Strings
3341
$json= Json::of('Test');
3442

3543
// Output
36-
$out= new FileOutput(new File('output.json'));
37-
$out= new StreamOutput(new SocketOuputStream(...));
44+
$out= new File('output.json');
45+
$out= new SocketOuputStream(/* ... */);
3846

3947
Json::write($value, $out);
4048
```
4149

4250
### Formatted output
43-
To change the output format, pass a `Format` instance to the output's constructor. The formats available are:
51+
To change the output format, use one of the `Output` implementations and pass a `Format` instance to the output's constructor. The formats available are:
4452

4553
* `DenseFormat($options)`: Best for network I/O, no unsignificant whitespace, default if nothing given and accessible via `Format::dense($options= ~Format::ESCAPE_SLASHES)`.
4654
* `WrappedFormat($indent, $options)`: Wraps first-level arrays and all objects, uses whitespace after commas colons. An instance of this format using 4 spaces for indentation and per default leaving forward slashes unescaped is available via `Format::wrapped($indent= " ", $options= ~Format::ESCAPE_SLASHES)`.
@@ -52,7 +60,9 @@ The available options that can be or'ed together are:
5260
* `Format::ESCAPE_ENTITIES`: Escape XML entities `&`, `"`, `<` and `>`. Per default, these are represented in their literal form.
5361

5462
```php
55-
$out= new FileOutput(new File('glue.json'), Format::wrapped());
63+
use text\json\{FileOutput, Format};
64+
65+
$out= new FileOutput('glue.json', Format::wrapped());
5666
$out->write([
5767
'name' => 'example/package',
5868
'version' => '1.0.0',

0 commit comments

Comments
 (0)