JSON

The JSON Component is a wrapper around php's json_encode and json_decode.

Installation

composer require sonsofphp/json

Usage

Json

<?php
use SonsOfPHP\Component\Json\Json;

// You use this as a drop-in replacement for json_encode and json_decode
$json = Json::encode($value);
$object = Json::decode($json);
$array = Json::decode($json, true);

// It comes with a JsonEncoder and JsonDecoder, see below for usage
$json = new Json();
$encoder = $json->getEncoder();
$decoder = $json->getDecoder();

JsonEncoder

JsonDecoder

Need Help?

Check out Sons of PHP's Organization Discussions.

Last updated

Was this helpful?