PHPackages                             php-enspired/simple-json - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. php-enspired/simple-json

ActiveLibrary

php-enspired/simple-json
========================

Convenience wrapper for json encoding/decoding.

2.0(5y ago)02GPL-3.0-onlyPHP

Since Oct 11Pushed 5y agoCompare

[ Source](https://github.com/php-enspired/simple-json)[ Packagist](https://packagist.org/packages/php-enspired/simple-json)[ RSS](/packages/php-enspired-simple-json/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

[![](https://camo.githubusercontent.com/6dd7d9cdb36fcd106ddf880d61ea7635b86d7026c89cc5c8bb55cea65e412c9d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7068702d656e7370697265642f73696d706c652d6a736f6e2e737667)](https://camo.githubusercontent.com/6dd7d9cdb36fcd106ddf880d61ea7635b86d7026c89cc5c8bb55cea65e412c9d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7068702d656e7370697265642f73696d706c652d6a736f6e2e737667) [![](https://camo.githubusercontent.com/9c852ca4661b0163b2d5229fd4948a8847e6d2361c60cb1906de163a0afb6c8f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e332d626c75652e7376673f636f6c6f72423d383839324246)](https://camo.githubusercontent.com/9c852ca4661b0163b2d5229fd4948a8847e6d2361c60cb1906de163a0afb6c8f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e332d626c75652e7376673f636f6c6f72423d383839324246) [![](https://camo.githubusercontent.com/22fbb1e95db502cb771880e417733267c3f3fb685df8ea2df8f80a7b9c6f6fdc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c5f332e305f6f6e6c792d626c75652e737667)](https://camo.githubusercontent.com/22fbb1e95db502cb771880e417733267c3f3fb685df8ea2df8f80a7b9c6f6fdc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c5f332e305f6f6e6c792d626c75652e737667)

it's simple: json
=================

[](#its-simple-json)

*Simple* packages are focused on being straightforward, clean, concise solutions for common needs.

*Json* is a convenience wrapper for json encoding/decoding. Its main purpose is to set sane defaults and make managing encoding/decoding options easy.

dependencies
------------

[](#dependencies)

Requires php 7.3 or later.

installation
------------

[](#installation)

Recommended installation method is via [Composer](https://getcomposer.org/): simply `composer require php-enspired/simple-json`.

basic usage
-----------

[](#basic-usage)

By default, objects are decoded as associative arrays and big integers are decoded as strings (rather than converting them to float).

When encoding data, big integers are encoded as strings, "zero" fractions are preserved (rather then encoding them as integers), and slashes and unicode characters are not escaped. To prevent unexpected/unpredictable results, objects will not be encoded unless they are `stdClass` or implement `JsonSerializable`.

Both encoding and decoding throw on error; this cannot be overridden.

Json defines some constants for sets of encode/decode options. As a convenience, these options are also settable via static factory methods.

- `ENCODE_ASCII`: default encoding options, but unsets `JSON_UNESCAPED_UNICODE`.
- `ENCODE_HEX`: all of the `JSON_HEX_*` options.
- `ENCODE_HTML`: default encoding options, but unsets `JSON_UNESCAPED_SLASHES`.
- `ENCODE_PRETTY`: default encoding options, and also sets `JSON_PRETTY_PRINT`.

```
