33PHP library to fix Truncated JSON data by padding contextual counterpart to the end. Works with PHP5.4 or above.
44
55[ ![ Latest Version] ( https://img.shields.io/github/release/adhocore/php-json-fixer.svg?style=flat-square )] ( https://github.com/adhocore/php-json-fixer/releases )
6- [ ![ Travis Build] ( https://img.shields.io/travis/ adhocore/php-json-fixer/master .svg?style=flat-square )] ( https://travis-ci.org /adhocore/php-json-fixer?branch=master )
6+ [ ![ Travis Build] ( https://travis-ci.com/ adhocore/php-json-fixer.svg?branch=master )] ( https://travis-ci.com /adhocore/php-json-fixer?branch=master )
77[ ![ Scrutinizer CI] ( https://img.shields.io/scrutinizer/g/adhocore/php-json-fixer.svg?style=flat-square )] ( https://scrutinizer-ci.com/g/adhocore/php-json-fixer/?branch=master )
88[ ![ Codecov branch] ( https://img.shields.io/codecov/c/github/adhocore/php-json-fixer/master.svg?style=flat-square )] ( https://codecov.io/gh/adhocore/php-json-fixer )
99[ ![ StyleCI] ( https://styleci.io/repos/141589074/shield )] ( https://styleci.io/repos/141589074 )
1010[ ![ Software License] ( https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square )] ( LICENSE )
1111
12- ** It is a work in progress and might not cover all edge cases**
12+ ** It is a work in progress and might not cover all edge cases. ** It would be great if you try it out, open some issues or contribute.
1313
1414## Installation
1515``` bash
@@ -33,7 +33,7 @@ $json = (new Fixer)->fix('{"b":[1,[{"b":1,"c"');
3333## Error
3434
3535If there's error and fixer cant fix the JSON for some reason, it will throw a ` RunttimeException ` .
36- You can disable this behavior by passing silent flag (2nd param) and in such case original input is returned:
36+ You can disable this behavior by passing silent flag (2nd param) to ` fix() ` in which case original input is returned:
3737
3838``` php
3939(new Fixer)->fix('invalid', true);
@@ -42,7 +42,7 @@ You can disable this behavior by passing silent flag (2nd param) and in such cas
4242
4343## Missing Value
4444
45- By default missing values are provided with ` null ` . You can change it by passing 3rd param to ` fix() `
45+ By default missing values are padded with ` null ` . You can change it by passing 3rd param to ` fix() ` :
4646
4747``` php
4848// key b is missing value and is padded with `null`
@@ -53,7 +53,9 @@ $json = (new Fixer)->fix('{"a":1,"b":');
5353$json = (new Fixer)->fix('{"a":1,"b":', false, 'true');
5454// {"a":1,"b":true}
5555
56- // key b is missing value and is padded with `true`
56+ // key b is missing value and is padded with `"truncated"`
57+ // Note that you can actually inject a whole new JSON subset as 3rd param
58+ // but that should be a valid JSON segment and is not checked by fixer.
5759$json = (new Fixer)->fix('{"a":1,"b":', false, '"truncated"');
5860// {"a":1,"b":"truncated"}
5961```
0 commit comments