PHPackages                             aternos/almost-json - 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. aternos/almost-json

ActiveLibrary

aternos/almost-json
===================

Parse all those weird things that should be JSON but someone decided to add weird quirks

v1.1.1(1y ago)48.5k↓38.7%MITPHP

Since Mar 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/aternosorg/php-almost-json)[ Packagist](https://packagist.org/packages/aternos/almost-json)[ RSS](/packages/aternos-almost-json/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

aternos/almost-json
===================

[](#aternosalmost-json)

A library to parse all those things that are kind of JSON but not quite.

Why?
----

[](#why)

Over the years, many accidentally or intentionally broken JSON parsers have emerged. If a software uses such a parser, users of that software might start writing broken JSON that is accepted by that parser, but not actually valid.
This makes writing code that deals with files originally created for such software very annoying, since some files will just randomly not work with a standard JSON parser because someone decided that wrapping a string in quotes was just way too much work for them.

This library aims to correctly parse normal JSON, while also accommodating as many weird quirks as possible.

Supported JSON quirks
---------------------

[](#supported-json-quirks)

When parsing valid JSON, this library should return the exact same result as PHP's built-in `json_decode` function. Additionally, the following quirks are supported:

- Line comments (`//` and `#`)
- Block comments (`/* ... */`)
- Objects
    - Unquoted keys
    - Missing or additional commas
    - Implicit close at end of input
- Arrays
    - Missing or additional commas
    - Implicit close at end of input
- Strings
    - Single quotes (`'`) instead of double quotes (`"`)
    - Backticks (```) instead of double quotes (`"`)
    - Unquoted strings
    - Escape sequences `\v` and `\0`
    - Ignore invalid escape sequences (e.g. `\a` =&gt; `a`)
    - Line continuation (`\` at the end of a line)
    - Literal newlines
- Numbers
    - Hexadecimal numbers (`0x...`)
    - Binary numbers (`0b...`)
    - Octal numbers (`0o...`)
    - Octal numbers with only `0` as prefix (`0...`) (not enabled by default)
    - Allow leading zeros (e.g. `0123`) for decimal numbers if octal numbers are enabled
    - Exponential notation with `e` or `E`
    - Underscores in numbers (e.g. `1_000_000`)
    - Decimal numbers with a trailing dot (e.g. `1.`)
    - Decimal numbers with a leading dot (e.g. `.1`)
    - Float values `NaN`, `Infinity`, and `-Infinity`
- Case-insensitive boolean values
- Case-insensitive null
- Ignore additional data after end of root node

Usage
-----

[](#usage)

### Installation

[](#installation)

```
composer require aternos/almost-json
```

### Parsing

[](#parsing)

```
$parser = new \Aternos\AlmostJson\AlmostJsonParser();
$parsed = $parser->parseString('{key: "value"}', assoc: true);

// => ['key' => 'value']
```

By default, the parser will assume the string is encoded as UTF-8. To use a different encoding you can call the `parse` method, which accepts an `Input` object instead of a string.

```
$parser = new \Aternos\AlmostJson\AlmostJsonParser();

$input = new \Aternos\AlmostJson\Input('{key: "value"}', encoding: "ISO-8859-1");
$parsed = $parser->parse($input, assoc: true);
```

To automatically detect the correct encoding, you can pass the result of the `mb_detect_encoding` function.

### Options

[](#options)

There are a number of options that can be set for a parser instance.

```
$parser = new \Aternos\AlmostJson\AlmostJsonParser();
$parser->setMaxDepth(512) // Maximum depth of the JSON tree
    ->setZeroPrefixOctal(true) // Parse numbers with leading zero as octal
    ->setTopLevelUnquotedStringAllowed(true); // Allow the root of the JSON tree to be an unquoted string
```

Performance
-----------

[](#performance)

This library is almost certainly significantly slower than PHP's built-in JSON implementation. If performance is critical, and most files are expected to be valid JSON, it might make sense to first try to use the built-in JSON parser, and only fall back to this library if it fails.

```
try {
    $parsed = json_decode($string, true, flags: JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
    $parser = new \Aternos\AlmostJson\AlmostJsonParser();
    $parsed = $parser->parseString($string, assoc: true);
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance49

Moderate activity, may be stable

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~13 days

Total

4

Last Release

376d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/182e603c02f308d1036a1ecaba0b994665e87d13a86ff4550a96c9189a92c544?d=identicon)[aternos](/maintainers/aternos)

---

Top Contributors

[![KurtThiemann](https://avatars.githubusercontent.com/u/26512466?v=4)](https://github.com/KurtThiemann "KurtThiemann (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aternos-almost-json/health.svg)

```
[![Health](https://phpackages.com/badges/aternos-almost-json/health.svg)](https://phpackages.com/packages/aternos-almost-json)
```

PHPackages © 2026

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