From a5d1355a9bdf468f17b81a1e46de036b5c51eb78 Mon Sep 17 00:00:00 2001 From: Denis Brumann Date: Fri, 16 Oct 2020 14:14:25 +0200 Subject: [PATCH] Add context for json encoding/decoding. --- components/serializer.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/serializer.rst b/components/serializer.rst index 345642c9770..62752ebbb1b 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -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`` ~~~~~~~~~~~~~~~~~~~