cruxoft / bolt-json
JSON wrapper library built on the Bolt Framework
Installs: 50
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/cruxoft/bolt-json
Requires
- php: ^8.0
- ext-json: *
- cruxoft/bolt-core: ^0.10.0
Requires (Dev)
- cruxoft/dump: ^0.2.0
This package is auto-updated.
Last update: 2025-09-24 23:09:35 UTC
README
What is it?
A simple wrapper for dealing with JSON in PHP with built in error handling.
Installation
Can be installed using composer by running the following:
$ composer require cruxoft/bolt-json
Usage
Simple usage involves calling static encode
and decode
methods however initial work on an OOP interface has been included.
Encode
use Bolt\Json; try { $json = Json::encode(array("hello" => "world")); } catch (\Exception $exception) { die($exception->getMessage()); } var_dump($json);
Outputs:
string(17) "{"hello":"world"}"
Decode
use Bolt\Json; try { $json = Json::decode('{"hello":"world"}'); } catch (\Exception $exception) { die($exception->getMessage()); } var_dump($json);
Outputs:
object(stdClass)#3 (1) {
["hello"]=>
string(5) "world"
}
Validate
use Bolt\Json; var_dump(Json::validate('{"hello":"world"}')); var_dump(Json::validate('{"hello":"world"x}'));
Outputs:
bool(true)
bool(false)
OOP
The class constructor takes either encoded or decoded data and allows manipulation of the data and output.
Very much a work in progress.
use Bolt\Json; $json = new Json(array("hello" => "world")); var_dump($json->toString());