… | |
… | |
239 | This setting has no effect when decoding JSON texts. |
239 | This setting has no effect when decoding JSON texts. |
240 | |
240 | |
241 | Example, space_before and indent disabled, space_after enabled: |
241 | Example, space_before and indent disabled, space_after enabled: |
242 | |
242 | |
243 | {"key": "value"} |
243 | {"key": "value"} |
|
|
244 | |
|
|
245 | $json = $json->relaxed ([$enable]) |
|
|
246 | If $enable is true (or missing), then "decode" will accept some |
|
|
247 | extensions to normal JSON syntax (see below). "encode" will not be |
|
|
248 | affected in anyway. *Be aware that this option makes you accept |
|
|
249 | invalid JSON texts as if they were valid!*. I suggest only to use |
|
|
250 | this option to parse application-specific files written by humans |
|
|
251 | (configuration files, resource files etc.) |
|
|
252 | |
|
|
253 | If $enable is false (the default), then "decode" will only accept |
|
|
254 | valid JSON texts. |
|
|
255 | |
|
|
256 | Currently accepted extensions are: |
|
|
257 | |
|
|
258 | * list items can have an end-comma |
|
|
259 | JSON *separates* array elements and key-value pairs with commas. |
|
|
260 | This can be annoying if you write JSON texts manually and want |
|
|
261 | to be able to quickly append elements, so this extension accepts |
|
|
262 | comma at the end of such items not just between them: |
|
|
263 | |
|
|
264 | [ |
|
|
265 | 1, |
|
|
266 | 2, <- this comma not normally allowed |
|
|
267 | ] |
|
|
268 | { |
|
|
269 | "k1": "v1", |
|
|
270 | "k2": "v2", <- this comma not normally allowed |
|
|
271 | } |
244 | |
272 | |
245 | $json = $json->canonical ([$enable]) |
273 | $json = $json->canonical ([$enable]) |
246 | If $enable is true (or missing), then the "encode" method will |
274 | If $enable is true (or missing), then the "encode" method will |
247 | output JSON objects by sorting their keys. This is adding a |
275 | output JSON objects by sorting their keys. This is adding a |
248 | comparatively high overhead. |
276 | comparatively high overhead. |