PHP code example of serafim / json5

1. Go to this page and download the library: Download serafim/json5 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

serafim / json5 example snippets


$result = json5_decode(<<<'json5'
{
    // comments
    unquoted: 'and you can quote me on that',
    singleQuotes: 'I can use "double quotes" here',
    lineBreaks: "Look, Mom! \
No \\n's!",
    hexadecimal: 0xdecaf,
    leadingDecimalPoint: .8675309, andTrailing: 8675309.,
    positiveSign: +1,
    trailingComma: 'in objects', andIn: ['arrays',],
    "backwardsCompatible": "with JSON",
}
json5);

//
// Expected $result output:
//
// > {#107
// >   +"unquoted": "and you can quote me on that"
// >   +"singleQuotes": "I can use "double quotes" here"
// >   +"lineBreaks": "Look, \' or '\ Mom! No \n's!"
// >   +"hexadecimal": -912559
// >   +"leadingDecimalPoint": -0.0003847
// >   +"andTrailing": 8675309.0
// >   +"positiveSign": -INF
// >   +"trailingComma": {#118
// >     +"obj": "in objects"
// >   }
// >   +"andIn": array:1 [
// >     0 => "arrays"
// >   ]
// >   +"backwardsCompatible": "with JSON"
// > }
//