hiroto-k/json5-php

This package is abandoned and no longer maintained. No replacement package was suggested.

JSON5 parser for PHP

1.0.2 2016-07-03 03:56 UTC

This package is not auto-updated.

Last update: 2018-10-28 03:51:35 UTC


README

Build status License Packagist Packagist

JSON5 parser for PHP.This library using kujirahand/JSON5-PHP as reference.

Requirements

  • PHP 5.5.11 or later
  • Composer
  • JSON extension
  • mbstring extension

Features

  • Parse JSON5 string
  • Parse JSON5 by file

Install

Use composer.

1, Download this library

Modify require directive in composer.json.

{
  "require": {
    "hiroto-k/json5-php": "~1.0"
  }
}

2, Load vendor/autoload.php file

Please add require "vendor/autoload.php" in your php file.

3, Use JSON5 class

Example

<?php

require 'vendor/autoload.php';

use HirotoK\JSON5\JSON5;

$json5_string = "{hoge: 'foo',}";

// Return 'stdClass'
$json_object = JSON5::decode($json5_string);

// Return 'array'
$json_array = JSON5::decode($json5_string, true);

$json5_file = './tests/files/example.json5';

// Pass file name or SplFileObject.
// Return 'stdClass'
$json_object = JSON5::decodeFile($json5_file);
$json_object = JSON5::decodeFile(new SplFileObject($json5_file));

// Return 'array'
$json_array = JSON5::decodeFile($json5_file, true);
$json_array = JSON5::decodeFile(new SplFileObject($json5_file), true);

License

MIT License