posternak/json-file
Composer 安装命令:
composer require posternak/json-file
包简介
A PHP utility library to ergonomically work with JSON files.
README 文档
README
A small PHP utility library for ergonomically reading, mutating, and writing JSON files.
Requirements
- PHP 8.2+
Installation
composer require posternak/json-file
Usage
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
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
MIT
posternak/json-file 适用场景与选型建议
posternak/json-file 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「file-manipulation」 「json-file」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 posternak/json-file 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 posternak/json-file 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 posternak/json-file 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
Get wordpress nav menus and share the main site menus with the child sites.
JPOPHP (JSON Parser Object PHP) is a library for parsing the data in JSON format.
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-10