2017 © Pedro Peláez
 

library jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its superseding) RFC 7159.

image

cmpayments/jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its superseding) RFC 7159.

  • Friday, March 25, 2016
  • by boywijnmaalen
  • Repository
  • 6 Watchers
  • 4 Stars
  • 1,525 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 45 Forks
  • 0 Open issues
  • 6 Versions
  • 17 % Grown

The README.md

JSON Lint for PHP Build Status

License Latest Stable Version Scrutinizer Code Quality Total Downloads Reference Status, (*1)

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its superseding) RFC 7159., (*2)

Usage

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)

Installation

For a quick install with Composer use:, (*3)

$ composer require cmpayments/jsonlint

JSON Lint for PHP can easily be used within another app if you have a PSR-4 autoloader, or it can be installed through Composer., (*4)

Requirements

  • PHP 5.4+
  • [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub, (*5)

Todo

  • [ ] Add support for keys without double quotes*

*RFC 4627 states that an object is an unordered collection of zero or more key/value pairs, where a key is a string and a value is a string, number, boolean, null, object, or array. This JSON linter tends to be more lenient towards keys without quotes in order to accept request from a JavaScript frontend., (*6)

Author

Boy Wijnmaalen - boy.wijnmaalen@cmtelecom.com - https://twitter.com/boywijnmaalen, (*7)

License

JSON Lint is licensed under the MIT License - see the LICENSE file for details, (*8)

Acknowledgements

This library is based on Seldaek/jsonlint and zaach/jsonlint., (*9)

The Versions

25/03 2016

dev-master

9999999-dev https://github.com/cmpayments/jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its superseding) RFC 7159.

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

parser lint php json validator syntax linter syntaxcheck

25/03 2016

v0.0.5

0.0.5.0 https://github.com/cmpayments/jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its superseding) RFC 7159.

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

parser lint php json validator syntax linter syntaxcheck

21/01 2016

v0.0.4

0.0.4.0 https://github.com/cmpayments/jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its superseding) RFC 7159.

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

parser lint php json validator syntax linter syntaxcheck

21/12 2015

v0.0.3

0.0.3.0 https://github.com/cmpayments/jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (message especially meant for APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its supeceding) RFC 7159

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

parser lint php json validator linter syntax check

18/12 2015

v0.0.2

0.0.2.0 https://github.com/cmpayments/jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

parser lint php json validator linter syntax check

17/12 2015

v0.0.1

0.0.1.0 https://github.com/cmpayments/jsonlint

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

parser lint php json validator linter syntax check