Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

redcatphp/JSON5-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

No longer actively maintained. I work now with NodeJS and I recommand you to take a look at json5

JSON5-php

Build status License

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