adhocore/json-comment

Lightweight JSON comment stripper library for PHP

Fund package maintenance!
paypal.me/ji10

0.1.0 2020-01-03 13:51 UTC

This package is auto-updated.

Last update: 2020-11-21 13:26:17 UTC


README

Latest Version Travis Build Scrutinizer CI Codecov branch StyleCI Software License

  • 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 */.

Installation

composer require adhocore/json-comment

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 Comment)->strip($someJsonText);

// Strip and decode!
(new Comment)->decode($someJsonText);

// You can pass args like in `json_decode`
(new Comment)->decode($someJsonText, $assoc = true, $depth = 512, $options = JSON_BIGINT_AS_STRING);

// Or you can use static alias of decode:
Comment::parse($json, true);