run:R W Run
DIR
2026-04-08 19:35:12
R W Run
DIR
2026-04-08 19:50:40
R W Run
2.07 KB
2026-04-08 19:29:49
R W Run
1.03 KB
2026-04-08 19:29:49
R W Run
2.92 KB
2026-04-08 19:29:49
R W Run
error_log
📄README.md
1JSON Lint
2=========
3
4[![Build Status](https://secure.travis-ci.org/Seldaek/jsonlint.png)](http://travis-ci.org/Seldaek/jsonlint)
5
6Usage
7-----
8
9```php
10use Seld\JsonLint\JsonParser;
11
12$parser = new JsonParser();
13
14// returns null if it's valid json, or a ParsingException object.
15$parser->lint($json);
16
17// Call getMessage() on the exception object to get
18// a well formatted error message error like this
19
20// Parse error on line 2:
21// ... "key": "value" "numbers": [1, 2, 3]
22// ----------------------^
23// Expected one of: 'EOF', '}', ':', ',', ']'
24
25// Call getDetails() on the exception to get more info.
26
27// returns parsed json, like json_decode() does, but slower, throws
28// exceptions on failure.
29$parser->parse($json);
30```
31
32You can also pass additional flags to `JsonParser::lint/parse` that tweak the functionality:
33
34- `JsonParser::DETECT_KEY_CONFLICTS` throws an exception on duplicate keys.
35- `JsonParser::ALLOW_DUPLICATE_KEYS` collects duplicate keys. e.g. if you have two `foo` keys they will end up as `foo` and `foo.2`.
36- `JsonParser::PARSE_TO_ASSOC` parses to associative arrays instead of stdClass objects.
37
38Example:
39
40```php
41$parser = new JsonParser;
42try {
43 $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
44} catch (DuplicateKeyException $e) {
45 $details = $e->getDetails();
46 echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
47}
48```
49
50> **Note:** This library is meant to parse JSON while providing good error messages on failure. There is no way it can be as fast as php native `json_decode()`.
51>
52> It is recommended to parse with `json_decode`, and when it fails parse again with seld/jsonlint to get a proper error message back to the user. See for example [how Composer uses this library](https://github.com/composer/composer/blob/56edd53046fd697d32b2fd2fbaf45af5d7951671/src/Composer/Json/JsonFile.php#L283-L318):
53
54
55Installation
56------------
57
58For a quick install with Composer use:
59
60 $ composer require seld/jsonlint
61
62JSON Lint can easily be used within another app if you have a
63[PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md)
64autoloader, or it can be installed through [Composer](https://getcomposer.org/)
65for use as a CLI util.
66Once installed via Composer you can run the following command to lint a json file or URL:
67
68 $ bin/jsonlint file.json
69
70Requirements
71------------
72
73- PHP 5.3+
74- [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)
75
76Submitting bugs and feature requests
77------------------------------------
78
79Bugs and feature request are tracked on [GitHub](https://github.com/Seldaek/jsonlint/issues)
80
81Author
82------
83
84Jordi Boggiano - <j.boggiano@seld.be> - <http://twitter.com/seldaek>
85
86License
87-------
88
89JSON Lint is licensed under the MIT License - see the LICENSE file for details
90
91Acknowledgements
92----------------
93
94This library is a port of the JavaScript [jsonlint](https://github.com/zaach/jsonlint) library.
95