eugene-melbourne / json-encoder-decoder
Encodes and Decodes JSON strings
Installs: 1 837
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- composer-runtime-api: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.0
README
Encodes and Decodes JSON strings
Installation
$ composer require eugene-melbourne/json-encoder-decoder
Most importantly it has default parameters pre-set
- JSON_THROW_ON_ERROR
- convertEmptyStringToNull
- ReturnAsAssociative
It can be changed though.
Also, it can ConvertEmptyStringToNull and has unit tests to see it in action.
Example:
// Example 1
$val = (new JsonEncoderDecoder())->json_encode(null)
// $val = null
// Example 2
$val = [chr(160),];
$json = (new JsonEncoderDecoder())->json_encode($val);
// throws JsonException
// Example 3
$val = [chr(160),];
$json = (new JsonEncoderDecoder())
->addOption(JSON_INVALID_UTF8_SUBSTITUTE)
->json_encode($val);
// $json = '["\ufffd"]';
See more examples in unit tests.
P.S.
The char code 160
would be