Skip to content

Commit a5d1355

Browse files
author
Denis Brumann
committed
Add context for json encoding/decoding.
1 parent 7e9385d commit a5d1355

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/serializer.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,13 @@ The ``JsonEncoder``
810810
~~~~~~~~~~~~~~~~~~~
811811

812812
The ``JsonEncoder`` encodes to and decodes from JSON strings, based on the PHP
813-
:phpfunction:`json_encode` and :phpfunction:`json_decode` functions.
813+
:phpfunction:`json_encode` and :phpfunction:`json_decode` functions. It can be
814+
useful to modify how these functions operate in certain instances by providing
815+
options such as ``JSON_PRESERVE_ZERO_FRACTION``. You can use the serialization
816+
context to pass in these options using the key ``json_encode_options`` or
817+
``json_decode_options`` respectively::
818+
819+
$this->serializer->serialize($data, 'json', ['json_encode_options' => \JSON_PRESERVE_ZERO_FRACTION]);
814820

815821
The ``CsvEncoder``
816822
~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)