@@ -12,13 +12,20 @@ the built in `json_encode` function, there are two main advantages:
12
12
memory, since the JSON document will be encoded value by value and it's
13
13
possible to output the encoded document piece by piece.
14
14
15
- In other words, the Streaming JSON encoder can provide the greatest benefit
16
- when you need handle large data sets that may otherwise take up too much memory
17
- to process.
15
+ In other words, the Streaming JSON Encoder can provide the greatest benefit
16
+ when you need to handle large data sets that may otherwise take up too much
17
+ memory to process.
18
18
19
19
In order to increase interoperability, the library also provides a PSR-7
20
20
compatible stream to use with frameworks and HTTP requests.
21
21
22
+ API documentation for the library can be generated using Sami and found
23
+ [ online] ( https://violet.riimu.net/api/streaming-json-encoder/ ) .
24
+
25
+ [ ![ Travis] ( https://img.shields.io/travis/violet-php/streaming-json-encoder.svg?style=flat-square )] ( https://travis-ci.org/violet-php/streaming-json-encoder )
26
+ [ ![ Scrutinizer] ( https://img.shields.io/scrutinizer/g/violet-php/streaming-json-encoder.svg?style=flat-square )] ( https://scrutinizer-ci.com/g/violet-php/streaming-json-encoder/ )
27
+ [ ![ Scrutinizer Coverage] ( https://img.shields.io/scrutinizer/coverage/g/violet-php/streaming-json-encoder.svg?style=flat-square )] ( https://scrutinizer-ci.com/g/violet-php/streaming-json-encoder/ )
28
+
22
29
## Requirements ##
23
30
24
31
In order to use this library, the following requirements must be met:
@@ -61,7 +68,7 @@ the installation.
61
68
### Manual installation ###
62
69
63
70
If you do not wish to use Composer to load the library, you may also download
64
- the library manually by downloading the [ latest release] ( https://github.com/violet/streaming-json-encoder/releases/latest )
71
+ the library manually by downloading the [ latest release] ( https://github.com/violet-php /streaming-json-encoder/releases/latest )
65
72
and extracting the ` src ` folder to your project. You may then include the
66
73
provided ` src/autoload.php ` file to load the library classes.
67
74
@@ -109,10 +116,9 @@ foreach ($encoder as $string) {
109
116
}
110
117
```
111
118
112
- It's also worth noting that the encoder also supports iterators for values.
113
- What's more, any closure passed to the encoder will also be called and the
114
- return value used as the value instead. The previous example could also be
115
- written as:
119
+ It's also worth noting that the encoder supports iterators for values. What's
120
+ more, any closure passed to the encoder will also be called and the return value
121
+ used as the value instead. The previous example could also be written as:
116
122
117
123
``` php
118
124
<?php
@@ -225,34 +231,36 @@ array, the encoder makes the following decisions:
225
231
* Only arrays that have keys from 0 to n-1 in that order are encoded as JSON
226
232
arrays. All other arrays are encoded as objects.
227
233
* Any object is encoded as a JSON array if the key of the first value
228
- returned by iterating over the objects equals to ` 0 ` . All other objects are
234
+ returned by iterating over the object equals to ` 0 ` . All other objects are
229
235
encoded as JSON objects.
230
236
231
237
Additionally, prior to the decision whether to encode an object as an array or
232
- an object is made, the encoder will attempt to resolve the value as follows:
238
+ as an object is made, the encoder will attempt to resolve the value as follows:
233
239
234
- * As long as the processed value is a ` JsonSerializable ` , it will replace the
235
- processed value with the return value of the ` jsonSerialize() ` method.
240
+ * As long as the processed value is a ` JsonSerializable ` , the encoder will
241
+ replace the processed value with the return value of the ` jsonSerialize() `
242
+ method.
236
243
* As long as the processed value is a ` Closure ` , it will be replaced with the
237
- value returned by invoking the closure in question .
244
+ value returned by invoking the closure.
238
245
239
- Note that it's possible to override the array or object decision by using the
240
- ` JSON_FORCE_OBJECT ` option.
246
+ Note that it's possible to override the decision between an array or an object
247
+ by using the ` JSON_FORCE_OBJECT ` option, which will force all objects and arrays
248
+ to be encoded as JSON objects.
241
249
242
250
### JSON encoding options ###
243
251
244
252
Both ` BufferJsonEncoder ` and ` StreamJsonEncoder ` have a method ` setOptions() ` to
245
253
change the JSON encoding options. The accepted options are the same as those
246
254
accepted by ` json_encode() ` function. The encoder still internally uses the
247
- ` json_encode() ` method to encode other values than arrays or object. A few
255
+ ` json_encode() ` method to encode values other than arrays or object. A few
248
256
options also have additional effects on the encoders:
249
257
250
- * Using ` JSON_FORCE_OBJECT ` will force all arrays and values to be encoded
258
+ * Using ` JSON_FORCE_OBJECT ` will force all arrays and objects to be encoded
251
259
as JSON objects similar to ` json_encode() ` .
252
- * Using ` JSON_PRETTY_PRINT ` causes the encoder to output whitespace to make
253
- a more readable output. The indentation used can be changed using the
254
- method ` setIndent() ` which accepts either a string argument to use as the
255
- indent or an integer to indicate the number of spaces.
260
+ * Using ` JSON_PRETTY_PRINT ` causes the encoder to output whitespace to in
261
+ order to make the output more readable . The used indentation can be changed
262
+ using the method ` setIndent() ` which accepts either a string argument to use
263
+ as the indent or an integer to indicate the number of spaces.
256
264
* Using ` JSON_PARTIAL_OUTPUT_ON_ERROR ` will cause the encoder to continue the
257
265
output despite encoding errors. Otherwise the encoding will halt and the
258
266
encoder will throw an ` EncodingException ` .
0 commit comments