https://github.com/yiisoft/json
JSON encoding and decoding
https://github.com/yiisoft/json
decoding encoding hacktoberfest json yii3
Last synced: 4 months ago
JSON representation
JSON encoding and decoding
- Host: GitHub
- URL: https://github.com/yiisoft/json
- Owner: yiisoft
- License: bsd-3-clause
- Created: 2019-07-25T08:49:55.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T15:08:23.000Z (about 1 year ago)
- Last Synced: 2024-04-14T00:25:55.349Z (about 1 year ago)
- Topics: decoding, encoding, hacktoberfest, json, yii3
- Language: PHP
- Homepage: https://www.yiiframework.com/
- Size: 92.8 KB
- Stars: 26
- Watchers: 19
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
Yii JSON
[](https://packagist.org/packages/yiisoft/json)
[](https://packagist.org/packages/yiisoft/json)
[](https://github.com/yiisoft/json/actions)
[](https://scrutinizer-ci.com/g/yiisoft/json/?branch=master)
[](https://scrutinizer-ci.com/g/yiisoft/json/?branch=master)
[](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/json/master)
[](https://github.com/yiisoft/json/actions?query=workflow%3A%22static+analysis%22)
[](https://shepherd.dev/github/yiisoft/json)The package provides methods to encode and decode JSON.
- It always throws `\JsonException` instead of returning false on error.
- It has sensible defaults, so you don't have to specify flags all the time.
- It has handy method to encode for HTML safely.
- It handles `\JsonSerializable`, `\DateTimeInterface`, and `\SimpleXMLElement` well.## Requirements
- PHP 7.4 or higher.
- `JSON` PHP extension.
- `SimpleXML` PHP extension.## Installation
The package could be installed with [Composer](https://getcomposer.org):
```shell
composer require yiisoft/json
```## General usage
Encoding:
```php
use \Yiisoft\Json\Json;$data = ['name' => 'Alex', 'team' => 'Yii'];
$json = Json::encode($data);
```Encoding for HTML:
```php
use \Yiisoft\Json\Json;$data = ['name' => 'Alex', 'team' => 'Yii'];
$json = Json::htmlEncode($data);
```Decoding:
```php
use \Yiisoft\Json\Json;$json = '{"name":"Alex","team":"Yii"}';
$data = Json::decode($json);
```## Documentation
- [Internals](docs/internals.md)
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).## License
The Yii JSON is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.Maintained by [Yii Software](https://www.yiiframework.com/).
## Support the project
[](https://opencollective.com/yiisoft)
## Follow updates
[](https://www.yiiframework.com/)
[](https://twitter.com/yiiframework)
[](https://t.me/yii3en)
[](https://www.facebook.com/groups/yiitalk)
[](https://yiiframework.com/go/slack)