A powerful and fluent JSON utility class for PHP with dot-notation access and custom exception handling.

v1.0.0 2025-06-22 11:23 UTC

This package is auto-updated.

Last update: 2025-06-22 11:33:02 UTC


README

A powerful and fluent JSON utility class for PHP with dot-notation access and custom exception handling.

🚀 Features

  • Dot-notation access (get('user.name'))
  • Fluent method chaining (set()->remove()->toJson())
  • Safe JSON parsing and encoding with exception support
  • Supports both associative arrays and objects
  • PSR-4 autoloading, modern PHP 8.1+

📦 Installation

Install via Composer:

composer require samluvanda/json

🧱 Usage Example

use Json\Json;

$json = new Json('{"user": {"name": "Alice"}}');

echo $json->get('user.name'); // Alice

$json->set('user.age', 30)
     ->remove('user.name');

echo $json->toJson(); // {"user":{"age":30}}

📘 API Overview

Method Description
__construct($json) Load JSON string
Json::parse($json) Decode JSON string into PHP data
Json::stringify($val) Encode PHP value into JSON string
Json::isValid($json) Validate JSON string
get($path, $default) Dot-notation key access
set($path, $value) Set nested key
has($path) Check if path exists
remove($path) Remove nested key
toJson() Convert to JSON string
all() Get raw PHP structure

🤝 Contributing

Contributions are welcome! If you'd like to improve this library:

  1. Fork the repository
  2. Create a new branch
  3. Make your changes
  4. Submit a pull request

Please ensure your code follows PSR standards and includes relevant tests where applicable.

📄 License

This project is licensed under the MIT License.