PHP code example of cmpayments / jsonlint

1. Go to this page and download the library: Download cmpayments/jsonlint 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/ */

    

cmpayments / jsonlint example snippets


use CMPayments\JsonLint\JsonLinter;

$linter = new JsonLinter();

// example JSON
$json = '{
    "id": 2,
    "name": "JSON Parser test",
    \'dimensions\': {
        "length": 7.0,
        "width": 12.0,
        "height": 9.5
    }
}';

// returns null if it's valid json, or a ParseException object.
$result = $linter->lint($json);

// Call $result->getMessage() on the ParseException object to get a well formatted error message error like this:
// You used single quotes instead of double quotes on string 'dimensions' on line 4 at column 9. It appears you have an extra trailing comma

// Call $result->getDetails() on the exception to get more info.
$result->getDetails();

// $result->getDetails() returns;
array (size=6)
  'errorCode' => int 3
  'match' => string 'dimensions' (length=10)
  'token' => string 'INVALID' (length=7)
  'line' => int 3
  'column' => int 9
  'expected' =>
    array (size=1)
      0 => string 'STRING' (length=6)