Download the PHP package aegisora/json-rule without Composer
On this page you can find all versions of the php package aegisora/json-rule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/json-rule
More information about aegisora/json-rule
Files in aegisora/json-rule
Package json-rule
Short Description JSON Rule provides a simple, rule-based JSON validation implementation for the Aegisora ecosystem.
License MIT
Homepage https://github.com/Aegisora/json-rule
Informations about the package json-rule
Aegisora JSON Rule
JSON Rule provides a simple, rule-based JSON validation implementation for the Aegisora ecosystem.
It is built on top of aegisora/rule-contract and follows its strict validation architecture, ensuring consistent and predictable behavior across applications.
This rule is useful for validating webhook payloads, API request bodies, configuration strings, message queue messages, and any other string that must contain well-formed JSON.
๐ Table of Contents
- Features
- Installation
- Core Concept
- Basic Usage
- Valid vs Invalid
- Validation Result
- Guardian Usage
- Real-World Examples
- Factory Methods
- Architecture
- License
- Contributing
- Support
โจ Features
- ๐น Lightweight and dependency-free except
aegisora/rule-contract - ๐น Validates whether a string contains well-formed JSON
- ๐น Backed by native
json_decode()andjson_last_error() - ๐น Accepts any valid JSON value (objects, arrays, strings, numbers, booleans,
null) - ๐น Rejects non-string input as an invalid context
- ๐น Fully compatible with Aegisora validation pipeline
- ๐น Strict
ContextโResultvalidation flow - ๐น No raw booleans โ only structured results
- ๐น Safe execution via base
Ruleabstraction - ๐น Simple factory API (create)
- ๐น Ready to use out of the box
๐ฆ Installation
๐ Core Concept
This package implements a single validation rule:
- accepts a string value via
Context - checks whether the value is well-formed JSON
- returns a standardized
Result
Under the hood it wraps the common boilerplate:
into a reusable rule that reports its outcome through a Result object instead of a raw boolean.
๐๏ธ Basic Usage
โ Valid vs Invalid
The rule passes for any well-formed JSON value and fails for malformed input. Validation relies on the native JSON parser, so only strictly well-formed JSON is accepted.
Valid JSON
Invalid JSON
๐งช Validation Result
If the value is valid JSON, the rule returns a valid result.
$result->isValid(); // true
If the value is not valid JSON, the rule returns an invalid result.
If the context value is not a string, the rule throws:
Aegisora\RuleContract\Exceptions\InvalidRuleContextException
๐ Guardian Usage
This rule can be used together with aegisora/guardian to build fluent validation pipelines.
If the value is not valid JSON, Guardian throws the provided domain exception.
๐งญ Real-World Examples
JSON Rule is useful for validating string payloads before they are decoded or persisted.
Examples
๐งฉ Factory Methods
JsonRule::create();
- no arguments โ creates a new rule instance
JsonRule::create()->validate($context);
$contextโContextwrapping the string value to validate
๐๏ธ Architecture
This package relies on aegisora/rule-contract.
Flow:
validate()is calledContextis passed in- The string value is extracted from context (non-strings raise
InvalidRuleContextException) - The value is decoded with
json_decode() json_last_error()is checkedResultis returned โ valid on success, invalid with thejson_rulecode on failure
All logic is safely handled by Rule contract.
โ๏ธ License
This package is open-source and licensed under the MIT License. See the LICENSE for details.
๐ฑ Contributing
Contributions are welcome and greatly appreciated! See the CONTRIBUTING for details.
๐ Support
If you find this project useful, please consider giving it a star on GitHub!
It helps the project grow and motivates further development.