xoubaman / json
A simple JSON wrapper
Installs: 5 017
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.3
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.1
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-04-17 02:34:32 UTC
README
A simple JSON wrapper class.
Features:
- Encode arrays|objects
- Decode JSON strings
- Validate JSON strings
- Throw exceptions on failure
Nothing else. As said, it is simple.
Usage
Json::encode($input): string
: encodes into JSONJson::decode(string $json): array
: decodes a JSON into an arrayJson::fromString(string $json)
: new Json instance$json->isValid(): bool
: whether the provided JSON is valid or not$json->input(): string
: the input used for instantiation$json->error(): string
: the error description, empty if no error$json->errorCode(): int
: the error code, JSON_ERROR_NONE if no error$json->asArray(): array
: the input decoded, throws aRuntimeException
if not a valid JSON