adhocore/json-comment
- Lightweight JSON comment stripper library for PHP.
- Makes possible to have comment in any form of JSON data.
- Supported comments: single line
// comment
or multi line/* comment */
. - Also strips trailing comma at the end of array or object, eg
-
[1,2,,]
=>[1,2]
-
{"x":1,,}
=>{"x":1}
-
- Handles literal LF (newline/linefeed) within string notation so that we can have multiline string
- Supports JSON string inside JSON string (see ticket #15 and PR #16)
- Zero dependency (no vendor bloat).
Installation
composer require adhocore/json-comment
# for php5.6
composer require adhocore/json-comment:^0.2
Usage
use Ahc\Json\Comment
// The JSON string!
$someJsonText = '{"a":1,
"b":2,// comment
"c":3 /* inline comment */,
// comment
"d":/* also a comment */"d",
/* creepy comment*/"e":2.3,
/* multi line
comment */
"f":"f1",}';
// OR
$someJsonText = file_get_contents('...');
// Strip only!
(new
…