yiisoft/json

dev-master / 3.0.x-dev 2019-07-25 11:29 UTC

README

993323

Yii JSON


The package provides methods to encode and decode JSON.

  • It throws \JsonException even if PHP version is lower than 7.3.
  • It has sensible defaults so you don't have to specify flags all the time.
  • It has handy methods to encode for HTML safely.
  • It handles \JsonSerializable and \SimpleXMLElement well.

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage

General usage

Encoding:

use \Yiisoft\Json\Json;

$data = ['name' => 'Alex', 'team' => 'Yii'];
$json = Json::encode($data);

Encoding for HTML:

use \Yiisoft\Json\Json;

$data = ['name' => 'Alex', 'team' => 'Yii'];
$json = Json::htmlEncode($data);

Decoding:

use \Yiisoft\Json\Json;

$json = '{"name":"Alex","team":"Yii"}';
$data = Json::decode($json);