Json
API reference › yii › helpers › Json
Json is a helper class providing JSON data encoding and decoding.
It enhances the PHP built-in functions json_encode() and json_decode()
by supporting encoding JavaScript expressions and throwing exceptions when decoding fails.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$jsonErrorMessages static | array | List of JSON Error messages assigned to constant names for better handling of PHP <= 5.5. Default: ['JSON_ERROR_SYNTAX' => 'Syntax error',. Available since 2.0.7. | BaseJson |
$keepObjectType static | bool | Avoids objects with zero-indexed keys to be encoded as array Json::encode((object)['test']) will be encoded as an object not as an array. Default: false. Available since 2.0.44. | BaseJson |
$prettyPrint static | bool| | Enables human readable output a.k.a. Default: null. Available since 2.0.43. | BaseJson |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
decode() static | Decodes the given JSON string into a PHP data structure. | BaseJson |
encode() static | Encodes the given value into a JSON string. | BaseJson |
errorSummary() static | Generates a summary of the validation errors. | BaseJson |
htmlEncode() static | Encodes the given value into a JSON string HTML-escaping entities so it is safe to be embedded in HTML code. | BaseJson |
handleJsonError() protected static | Handles encode() and decode() errors by throwing exceptions with the respective error message. | BaseJson |
processData() protected static | Pre-processes the data before sending it to json_encode(). | BaseJson |