8ctopus/relaxed-json

Tired of JSON's super strict syntax? Then relaxed JSON if for you.

1.0.2 2023-12-28 11:18 UTC

This package is auto-updated.

Last update: 2024-04-28 12:01:04 UTC


README

packagist downloads min php version license tests code coverage badge lines of code

Tired of JSON's super strict syntax? Then relaxed JSON if for you.

features

  • supports comments in all forms // my comment, /* my comment */
  • ignores trailing commas at the end of an array or object
  • throws an Exception when the json is invalid
  • zero dependencies

install

composer require 8ctopus/relaxed-json

usage

use Oct8pus\RelaxedJson;

$json = <<<JSON
{
    // maximum requests per hour
    "throttleThreshold": 300,
}

JSON;

var_dump(RelaxedJson::decode($json, true));
array(1) {
  'name' =>
  string(20) "8ctopus/relaxed-json"
}

exceptions

$json = <<<JSON
{
    "throttleThreshold" => 300,
}

JSON;

// throws RelaxedJsonException Syntax error
RelaxedJson::decode($json, true);

credits

This library is are repack with improvements of the original work from https://github.com/etconsilium/php-json-fix

tests

composer test

clean code

composer fix
composer fix-risky