PHPackages                             posternak/json-file - 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. posternak/json-file

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

posternak/json-file
===================

A PHP utility library to ergonomically work with JSON files.

1.0.0(1mo ago)091MITPHP ^8.2

Since Jun 10Compare

[ Source](https://github.com/Androoha1/json-file)[ Packagist](https://packagist.org/packages/posternak/json-file)[ RSS](/packages/posternak-json-file/feed)WikiDiscussions Synced 3w ago

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

json-file
=========

[](#json-file)

[![CI](https://github.com/Androoha1/json-file/actions/workflows/ci.yml/badge.svg)](https://github.com/Androoha1/json-file/actions/workflows/ci.yml)[![Latest Version](https://camo.githubusercontent.com/723542df5cb421f7a29b7c9ce52048217233da5810ef56debce500f6c77c6131/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706f737465726e616b2f6a736f6e2d66696c652e737667)](https://packagist.org/packages/posternak/json-file)[![PHP Version](https://camo.githubusercontent.com/48497d8f3bdc1ad6bc9b7ebb6aec0db361548402bc985e4bd85ce266314c7d3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706f737465726e616b2f6a736f6e2d66696c652e737667)](https://packagist.org/packages/posternak/json-file)[![License](https://camo.githubusercontent.com/49a92f66064b2082df3fae9c565b098f3d10bdf12b4a99d587d5e07107b62368/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706f737465726e616b2f6a736f6e2d66696c652e737667)](LICENSE)

A small PHP utility library for ergonomically reading, mutating, and writing JSON files.

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

[](#requirements)

- PHP 8.2+

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

[](#installation)

```
composer require posternak/json-file
```

Usage
-----

[](#usage)

### `JsonFile` — mutate a file via dot-notation paths

[](#jsonfile--mutate-a-file-via-dot-notation-paths)

Suppose you have `settings.json`:

```
{
    "appName": "Acme",
    "version": "0.4.2",
    "server": {
        "host": "localhost",
        "port": 8080,
        "tls": {
            "enabled": false
        }
    },
    "features": {
        "darkMode": true,
        "betaFlags": ["search-v2", "fast-export"]
    }
}
```

You can read, mutate, and persist values addressed by dot-notation paths:

```
use Posternak\JsonFile\JsonFile;

$file = new JsonFile('/path/to/settings.json');

// Check existence
$file->has('server.tls.enabled');                           // true
$file->has('features.nonexistent');                         // false

// Read — any JSON type comes back as-is
$name      = $file->get('appName');              // "Acme"
$port      = $file->get('server.port');          // 8080
$tlsOn     = $file->get('server.tls.enabled');   // false
$flags     = $file->get('features.betaFlags');   // ["search-v2", "fast-export"]
$tlsBlock  = $file->get('server.tls');           // ["enabled" => false]

// Write — strings, ints, bools, arrays, null, all fine
$file->set('version', '0.5.0');
$file->set('server.port', 9090);
$file->set('server.tls.enabled', true);

// Missing parents are created on the fly
$file->set('server.tls.certPath', '/etc/ssl/acme.pem');

// Remove
$file->remove('features.darkMode');

// Persist back to disk (pretty-printed)
$file->save();
```

Missing paths throw `RuntimeException` on `get`. `set` creates missing parents automatically. `remove` is a no-op when the path is missing.

If a key itself contains a `.` (e.g. an IP address or a version constraint used as a key), pass the path as a list of strings to skip splitting:

```
$file->get(['servers', '127.0.0.1', 'port']);
```

### `Json` — stateless helpers

[](#json--stateless-helpers)

```
use Posternak\JsonFile\Json;

$data = Json::decodeFile('/path/to/file.json');
Json::prettyPrintIntoFile($data, '/path/to/out.json');

// Re-pretty-print an existing file in place
Json::reprintFileContentInPrettyWay('/path/to/messy.json');
```

All `Json` methods throw `RuntimeException` on IO or JSON parse/encode failures.

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance91

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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 ~10 days

Total

3

Last Release

44d ago

Major Versions

v0.1.0 → v1.0.02026-05-27

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147425231?v=4)[androoha](/maintainers/androoha)[@Androoha](https://github.com/Androoha)

---

Tags

jsonjson filefile manipulation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/posternak-json-file/health.svg)

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k334.7M802](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k504.8M168](/packages/mtdowling-jmespathphp)[jms/serializer

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

2.3k141.9M937](/packages/jms-serializer)[jms/serializer-bundle

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

1.8k92.4M684](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30625.1M58](/packages/colinodell-json5)[clue/ndjson-react

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

15882.2M31](/packages/clue-ndjson-react)

PHPackages © 2026

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