PHPackages                             adhocore/json-comment - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. adhocore/json-comment

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

adhocore/json-comment
=====================

Lightweight JSON comment stripper library for PHP

1.2.1(3y ago)33629.7k—2.9%6[1 issues](https://github.com/adhocore/php-json-comment/issues)8MITPHPPHP &gt;=7.0CI failing

Since Aug 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/adhocore/php-json-comment)[ Packagist](https://packagist.org/packages/adhocore/json-comment)[ Fund](https://paypal.me/ji10)[ GitHub Sponsors](https://github.com/adhocore)[ RSS](/packages/adhocore-json-comment/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (16)Used By (8)

adhocore/json-comment
---------------------

[](#adhocorejson-comment)

[![Latest Version](https://camo.githubusercontent.com/e832cddefd90ce6bf77f6763631b03de5dc91cf7c0bb648a4748ba90999761cd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6164686f636f72652f7068702d6a736f6e2d636f6d6d656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/adhocore/php-json-comment/releases)[![Travis Build](https://camo.githubusercontent.com/a0acf0344b73cff90fabaada7e3ec28c1344b42aaef10ecd28d9345c5824eb17/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6164686f636f72652f7068702d6a736f6e2d636f6d6d656e742f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/adhocore/php-json-comment?branch=main)[![Scrutinizer CI](https://camo.githubusercontent.com/65ae1e367d3012efc4ec391102baf4e19a2427c7a1e5871b5731272b0eef6ff2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6164686f636f72652f7068702d6a736f6e2d636f6d6d656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/adhocore/php-json-comment/?branch=main)[![Codecov branch](https://camo.githubusercontent.com/ed915bc7a4d49e2eaf34e64693029fc8a0e737e829e4b3677367e93ba027fee3/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6164686f636f72652f7068702d6a736f6e2d636f6d6d656e742f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/adhocore/php-json-comment)[![StyleCI](https://camo.githubusercontent.com/c137e1a5a7fb8bdaa0f13ee735339dbb2fa3fd2c09b597b879bedad60146fdc2/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130303131373139392f736869656c64)](https://styleci.io/repos/100117199)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Tweet](https://camo.githubusercontent.com/cb820a0ecc9645168e33b03925d7f14691262ddbaeaf66a0a91697803d0cba2d/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=Flexible+JSON+parser+with+comments+and+newline+support+in+PHP&url=https://github.com/adhocore/php-json-comment&hashtags=php,json,flexible-json,json-comment)[![Support](https://camo.githubusercontent.com/6687993dc9b60228356720a501b7c197c8c9a82194cac1b1c72d0dea95e6ad32/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d537570706f7274266d6573736167653d254532253944254134266c6f676f3d476974487562)](https://github.com/sponsors/adhocore)

- Lightweight JSON comment stripper library for PHP.
- Makes possible to have comment in any form of JSON data.
- Supported comments: single line `// comment` or multi line `/* comment */`.
- Also strips trailing comma at the end of array or object, eg:
    - `[1,2,,]` =&gt; `[1,2]`
    - `{"x":1,,}` =&gt; `{"x":1}`
- Handles literal LF (newline/linefeed) within string notation so that we can have multiline string
- Supports JSON string inside JSON string (see ticket [\#15](https://github.com/adhocore/php-json-comment/issues/15) and PR [\#16](https://github.com/adhocore/php-json-comment/pull/16))
- Zero dependency (no vendor bloat).

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

[](#installation)

```
composer require adhocore/json-comment

# for php5.6
composer require adhocore/json-comment:^0.2
```

Usage
-----

[](#usage)

```
use Ahc\Json\Comment;

// The JSON string!
$someJsonText = '{"a":1,
"b":2,// comment
"c":3 /* inline comment */,
// comment
"d":/* also a comment */"d",
/* creepy comment*/"e":2.3,
/* multi line
comment */
"f":"f1",}';

// OR
$someJsonText = file_get_contents('...');

// Strip only!
(new Comment)->strip($someJsonText);

// Strip and decode!
(new Comment)->decode($someJsonText);

// You can pass args like in `json_decode`
(new Comment)->decode($someJsonText, $assoc = true, $depth = 512, $options = JSON_BIGINT_AS_STRING);

// Or you can use static alias of decode:
Comment::parse($json, true);

# Or use file directly
Comment::parseFromFile('/path/to/file.json', true);
```

### Example

[](#example)

An example JSON that this library can parse:

```
{
  "name": "adhocore/json-comment",
  "description": "JSON comment stripper library for PHP.
    There is literal line break just above this line but that's okay",
  "type":/* This is creepy comment */ "library",
  "keywords": [
    "json",
    "comment",
    // Single line comment, Notice the comma below:
    "strip-comment",
  ],
  "license": "MIT",
  /*
   * This is a multiline
   * comment.
   */
  "authors": [
    {
      "name": "Jitendra Adhikari",
      "email": "jiten.adhikary@gmail.com",
    },
  ],
  "autoload": {
      "psr-4": {
          "Ahc\\Json\\": "src/",
      },
  },
  "autoload-dev": {
      "psr-4": {
          "Ahc\\Json\\Test\\": "tests/",
      },
  },
  "require": {
      "php": ">=7.0",
      "ext-ctype": "*",
  },
  "require-dev": {
      "phpunit/phpunit": "^6.5 || ^7.5 || ^8.5",
  },
  "scripts": {
      "test": "phpunit",
      "echo": "echo '// This is not comment'",
      "test:cov": "phpunit --coverage-text",
  },
}
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 92.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 ~144 days

Recently: every ~136 days

Total

14

Last Release

1324d ago

Major Versions

0.2.0 → 1.0.02021-04-05

PHP version history (2 changes)v0.0.7PHP &gt;=5.4

1.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2908547?v=4)[Jitendra Adhikari](/maintainers/adhocore)[@adhocore](https://github.com/adhocore)

---

Top Contributors

[![adhocore](https://avatars.githubusercontent.com/u/2908547?v=4)](https://github.com/adhocore "adhocore (94 commits)")[![martijnengler](https://avatars.githubusercontent.com/u/929994?v=4)](https://github.com/martijnengler "martijnengler (5 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

adhocorecommenthacktoberfesthuman-jsonjsonjson-commentjson5json5-parserphpstrip-commentjsoncommentstrip-comment

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adhocore-json-comment/health.svg)

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[clue/ndjson-react

Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.

15467.7M16](/packages/clue-ndjson-react)

PHPackages © 2026

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