Skip to content

Setting options for json encode/decode in Serializer #14431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,13 @@ The ``JsonEncoder``
~~~~~~~~~~~~~~~~~~~

The ``JsonEncoder`` encodes to and decodes from JSON strings, based on the PHP
:phpfunction:`json_encode` and :phpfunction:`json_decode` functions.
:phpfunction:`json_encode` and :phpfunction:`json_decode` functions. It can be
useful to modify how these functions operate in certain instances by providing
options such as ``JSON_PRESERVE_ZERO_FRACTION``. You can use the serialization
context to pass in these options using the key ``json_encode_options`` or
``json_decode_options`` respectively::

$this->serializer->serialize($data, 'json', ['json_encode_options' => \JSON_PRESERVE_ZERO_FRACTION]);

The ``CsvEncoder``
~~~~~~~~~~~~~~~~~~~
Expand Down