Skip to content

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

License

Notifications You must be signed in to change notification settings

8ctopus/relaxed-json

Repository files navigation

relaxed json

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Languages