PHPackages                             seld/jsonlint - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. seld/jsonlint

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

seld/jsonlint
=============

JSON Linter

1.11.0(1y ago)1.3k217.8M—1.3%59[2 issues](https://github.com/Seldaek/jsonlint/issues)[3 PRs](https://github.com/Seldaek/jsonlint/pulls)20MITPHPPHP ^5.3 || ^7.0 || ^8.0

Since Mar 12Pushed 1y ago22 watchersCompare

[ Source](https://github.com/Seldaek/jsonlint)[ Packagist](https://packagist.org/packages/seld/jsonlint)[ GitHub Sponsors](https://github.com/Seldaek)[ Fund](https://tidelift.com/funding/github/packagist/seld/jsonlint)[ RSS](/packages/seld-jsonlint/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (28)Used By (20)

JSON Lint
=========

[](#json-lint)

[![Build Status](https://github.com/Seldaek/jsonlint/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/Seldaek/jsonlint/actions/workflows/continuous-integration.yml)

Usage
-----

[](#usage)

```
use Seld\JsonLint\JsonParser;

$parser = new JsonParser();

// returns null if it's valid json, or a ParsingException object.
$parser->lint($json);

// Call getMessage() on the exception object to get
// a well formatted error message error like this

// Parse error on line 2:
// ... "key": "value"    "numbers": [1, 2, 3]
// ----------------------^
// Expected one of: 'EOF', '}', ':', ',', ']'

// Call getDetails() on the exception to get more info.

// returns parsed json, like json_decode() does, but slower, throws
// exceptions on failure.
$parser->parse($json);
```

You can also pass additional flags to `JsonParser::lint/parse` that tweak the functionality:

- `JsonParser::DETECT_KEY_CONFLICTS` throws an exception on duplicate keys.
- `JsonParser::ALLOW_DUPLICATE_KEYS` collects duplicate keys. e.g. if you have two `foo` keys they will end up as `foo` and `foo.2`.
- `JsonParser::PARSE_TO_ASSOC` parses to associative arrays instead of stdClass objects.
- `JsonParser::ALLOW_COMMENTS` parses while allowing (and ignoring) inline `//` and multiline `/* */` comments in the JSON document.
- `JsonParser::ALLOW_DUPLICATE_KEYS_TO_ARRAY` collects duplicate keys. e.g. if you have two `foo` keys the `foo` key will become an object (or array in assoc mode) with all `foo` values accessible as an array in `$result->foo->__duplicates__` (or `$result['foo']['__duplicates__']` in assoc mode).

Example:

```
$parser = new JsonParser;
try {
    $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
    $details = $e->getDetails();
    echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
}
```

> **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()`.
>
> 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):

Installation
------------

[](#installation)

For a quick install with Composer use:

```
composer require seld/jsonlint
```

JSON Lint can easily be used within another app if you have a [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md)autoloader, or it can be installed through [Composer](https://getcomposer.org/)for use as a CLI util. Once installed via Composer you can run the following command to lint a json file or URL:

```
$ bin/jsonlint file.json

```

Requirements
------------

[](#requirements)

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

Submitting bugs and feature requests
------------------------------------

[](#submitting-bugs-and-feature-requests)

Bugs and feature request are tracked on [GitHub](https://github.com/Seldaek/jsonlint/issues)

Author
------

[](#author)

Jordi Boggiano -  -

License
-------

[](#license)

JSON Lint is licensed under the MIT License - see the LICENSE file for details

Acknowledgements
----------------

[](#acknowledgements)

This library is a port of the JavaScript [jsonlint](https://github.com/zaach/jsonlint) library.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity78

Solid adoption and visibility

Community50

Growing community involvement

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 68.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~173 days

Recently: every ~207 days

Total

27

Last Release

676d ago

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

1.4.0PHP ^5.3 || ^7.0

1.8.0PHP ^5.3 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b69782e1d7f426ef78f61d159c466a536372eff931f13981ac578fa3f4649352?d=identicon)[Seldaek](/maintainers/Seldaek)

---

Top Contributors

[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (120 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (8 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (4 commits)")[![martinlindhe](https://avatars.githubusercontent.com/u/181531?v=4)](https://github.com/martinlindhe "martinlindhe (4 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (3 commits)")[![Chris53897](https://avatars.githubusercontent.com/u/7104259?v=4)](https://github.com/Chris53897 "Chris53897 (3 commits)")[![clxmstaab](https://avatars.githubusercontent.com/u/47448731?v=4)](https://github.com/clxmstaab "clxmstaab (3 commits)")[![acataluddi](https://avatars.githubusercontent.com/u/8874358?v=4)](https://github.com/acataluddi "acataluddi (2 commits)")[![MAXakaWIZARD](https://avatars.githubusercontent.com/u/1138453?v=4)](https://github.com/MAXakaWIZARD "MAXakaWIZARD (2 commits)")[![DavidPrevot](https://avatars.githubusercontent.com/u/3936728?v=4)](https://github.com/DavidPrevot "DavidPrevot (2 commits)")[![asnyder](https://avatars.githubusercontent.com/u/199062?v=4)](https://github.com/asnyder "asnyder (2 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (2 commits)")[![firegate666](https://avatars.githubusercontent.com/u/1197926?v=4)](https://github.com/firegate666 "firegate666 (2 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (1 commits)")[![theofidry](https://avatars.githubusercontent.com/u/5175937?v=4)](https://github.com/theofidry "theofidry (1 commits)")[![vtsykun](https://avatars.githubusercontent.com/u/21358010?v=4)](https://github.com/vtsykun "vtsykun (1 commits)")[![ancarda](https://avatars.githubusercontent.com/u/3399778?v=4)](https://github.com/ancarda "ancarda (1 commits)")[![EdwardBetts](https://avatars.githubusercontent.com/u/3818?v=4)](https://github.com/EdwardBetts "EdwardBetts (1 commits)")[![FlorianSW](https://avatars.githubusercontent.com/u/4892966?v=4)](https://github.com/FlorianSW "FlorianSW (1 commits)")

---

Tags

jsonvalidatorparserlinter

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/seld-jsonlint/health.svg)

```
[![Health](https://phpackages.com/badges/seld-jsonlint/health.svg)](https://phpackages.com/packages/seld-jsonlint)
```

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[ergebnis/json-schema-validator

Provides a JSON schema validator, building on top of justinrainbow/json-schema.

3626.9M7](/packages/ergebnis-json-schema-validator)[geraintluff/jsv4

A (coercive) JSON Schema v4 Validator for PHP

115455.2k4](/packages/geraintluff-jsv4)[johnstevenson/json-works

Create, edit, query and validate json

272.5M6](/packages/johnstevenson-json-works)[evaisse/php-json-schema-generator

A JSON Schema Generator.

20298.5k1](/packages/evaisse-php-json-schema-generator)[dstotijn/yii2-json-schema-validator

A Yii2 extension that provides a validator class for JSON Schema validation.

1730.7k](/packages/dstotijn-yii2-json-schema-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
