PHPackages                             dnt/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dnt/json

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dnt/json
========

v1.3(4y ago)115MITPHPPHP ^8.1

Since Feb 17Pushed 4y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (5)Used By (0)

Json manager
------------

[](#json-manager)

date: 01:28 18/02/2022 coded by Ducnt

### Cách dùng

[](#cách-dùng)

#### 1. cài đặt

[](#1-cài-đặt)

`composer require dnt/json`

#### 2. khởi tạo

[](#2-khởi-tạo)

```
use DNT\Json\Json;

$json = Json::make(string $path, bool $ensure = false, int $mode = 0755, $recursive = true);
// hoặc
$json = new Json(string $path, bool $ensure = false, int $mode = 0755, $recursive = true);
```

- $path: đường dẫn đến file. Một đường dẫn hợp lệ là 1 đường dẫn đến 1 file có quyền đọc và ghi file
- $ensure: nếu `true` : file không tồn tại thì sẽ khởi tạo. Nếu `false` file không tồn tại sẽ ném ra exception `FileNotFoundException`
- $mode: quyền truy cập
- $recursive: nếu đường dẫn là xâu của nhiều thư mục thì có cho phép tạo các thư mục đó không

*Khi khởi tạo thì ngay lập tức sẽ tìm đến `$path` để đọc nó và `convert` qua `array`*

### 3. các hàm bổ trợ

[](#3-các-hàm-bổ-trợ)

```
    // đặt đường dẫn mới
	public function setPath(string $path): Jsonable;

    // lấy đường dẫn hiện hành
	public function getPath(): string;

    // lấy thuộc tính - nếu null hoặc không tồn tại thì sẽ lấy $default - $default có thể là 1 callable
	public function get(string $key, mixed $default = null): mixed;

    // chuyển sang dạng json
	public function toJson(int $flag = JSON_FORCE_OBJECT): string;

    // kiểm tra thuộc tính tồn tại không
	public function has($offset): bool;

    // đặt giữ liệu mới
	public function setAttributes(array $attributes = []): Jsonable;

    // lấy tất cả thuộc tính
	public function all(): array;

	// lưu các thay đổi vào file
	public function save(): bool;
```

- Ngoài ra có thể sử dụng:

```
use DNT\Json\Json;

$json=Json::make($path);

// Lấy thuộc tính tương tự $json->get('foo');
$json->foo;

 // đặt giá trị mới tương tự $json->set('foo','bar');
 $json->foo = 'bar';

 // sử dụng anonymous function
 $json->foo = function() {
    return 'bar';
 };
 // hoặc
 $json->set('foo',function(){
    return 'bar';
 });
 // cũng có thể dùng callback để lấy giá trị mặc định
 $json->get('foo',function(){
    return 'bar';
 });
```

### 4. test

[](#4-test)

`composer test`

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

4

Last Release

1541d ago

### Community

Maintainers

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

---

Top Contributors

[![ducconit](https://avatars.githubusercontent.com/u/72369814?v=4)](https://github.com/ducconit "ducconit (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[illuminate/support

The Illuminate Support package.

582107.1M34.5k](/packages/illuminate-support)[illuminate/collections

The Illuminate Collections package.

27071.5M822](/packages/illuminate-collections)[illuminate/events

The Illuminate Events package.

13454.3M1.8k](/packages/illuminate-events)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.0M314](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

224.3M122](/packages/illuminate-cookie)

PHPackages © 2026

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