@@ -102,7 +102,7 @@ Extending :class:`JSONEncoder`::
102102
103103.. highlight :: bash
104104
105- Using json.tool from the shell to validate and pretty-print::
105+ Using :mod: ` json.tool ` from the shell to validate and pretty-print::
106106
107107 $ echo '{"json":"obj"}' | python -m json.tool
108108 {
@@ -135,26 +135,27 @@ Basic Usage
135135 :term: `file-like object `) using this :ref: `conversion table
136136 <py-to-json-table>`.
137137
138- If *skipkeys * is `` True `` (default: ``False ``), then dict keys that are not
138+ If *skipkeys * is true (default: ``False ``), then dict keys that are not
139139 of a basic type (:class: `str `, :class: `int `, :class: `float `, :class: `bool `,
140140 ``None ``) will be skipped instead of raising a :exc: `TypeError `.
141141
142142 The :mod: `json ` module always produces :class: `str ` objects, not
143143 :class: `bytes ` objects. Therefore, ``fp.write() `` must support :class: `str `
144144 input.
145145
146- If *ensure_ascii * is `` True `` (the default), the output is guaranteed to
146+ If *ensure_ascii * is true (the default), the output is guaranteed to
147147 have all incoming non-ASCII characters escaped. If *ensure_ascii * is
148- `` False `` , these characters will be output as-is.
148+ false , these characters will be output as-is.
149149
150- If *check_circular * is `` False `` (default: ``True ``), then the circular
150+ If *check_circular * is false (default: ``True ``), then the circular
151151 reference check for container types will be skipped and a circular reference
152152 will result in an :exc: `OverflowError ` (or worse).
153153
154- If *allow_nan * is `` False `` (default: ``True ``), then it will be a
154+ If *allow_nan * is false (default: ``True ``), then it will be a
155155 :exc: `ValueError ` to serialize out of range :class: `float ` values (``nan ``,
156- ``inf ``, ``-inf ``) in strict compliance of the JSON specification, instead of
157- using the JavaScript equivalents (``NaN ``, ``Infinity ``, ``-Infinity ``).
156+ ``inf ``, ``-inf ``) in strict compliance of the JSON specification.
157+ If *allow_nan * is true, their JavaScript equivalents (``NaN ``,
158+ ``Infinity ``, ``-Infinity ``) will be used.
158159
159160 If *indent * is a non-negative integer or string, then JSON array elements and
160161 object members will be pretty-printed with that indent level. An indent level
@@ -174,10 +175,12 @@ Basic Usage
174175 .. versionchanged :: 3.4
175176 Use ``(',', ': ') `` as default if *indent * is not ``None ``.
176177
177- *default(obj) * is a function that should return a serializable version of
178- *obj * or raise :exc: `TypeError `. The default simply raises :exc: `TypeError `.
178+ If specified, *default * should be a function that gets called for objects that
179+ can't otherwise be serialized. It should return a JSON encodable version of
180+ the object or raise a :exc: `TypeError `. If not specified, :exc: `TypeError `
181+ is raised.
179182
180- If *sort_keys * is `` True `` (default: ``False ``), then the output of
183+ If *sort_keys * is true (default: ``False ``), then the output of
181184 dictionaries will be sorted by key.
182185
183186 To use a custom :class: `JSONEncoder ` subclass (e.g. one that overrides the
@@ -339,7 +342,7 @@ Encoders and Decoders
339342 ``'false' ``. This can be used to raise an exception if invalid JSON numbers
340343 are encountered.
341344
342- If *strict * is `` False `` (``True `` is the default), then control characters
345+ If *strict * is false (``True `` is the default), then control characters
343346 will be allowed inside strings. Control characters in this context are
344347 those with character codes in the 0-31 range, including ``'\t' `` (tab),
345348 ``'\n' ``, ``'\r' `` and ``'\0' ``.
@@ -402,26 +405,26 @@ Encoders and Decoders
402405 for ``o `` if possible, otherwise it should call the superclass implementation
403406 (to raise :exc: `TypeError `).
404407
405- If *skipkeys * is `` False `` (the default), then it is a :exc: `TypeError ` to
408+ If *skipkeys * is false (the default), then it is a :exc: `TypeError ` to
406409 attempt encoding of keys that are not str, int, float or None. If
407- *skipkeys * is `` True `` , such items are simply skipped.
410+ *skipkeys * is true , such items are simply skipped.
408411
409- If *ensure_ascii * is `` True `` (the default), the output is guaranteed to
412+ If *ensure_ascii * is true (the default), the output is guaranteed to
410413 have all incoming non-ASCII characters escaped. If *ensure_ascii * is
411- `` False `` , these characters will be output as-is.
414+ false , these characters will be output as-is.
412415
413- If *check_circular * is `` True `` (the default), then lists, dicts, and custom
416+ If *check_circular * is true (the default), then lists, dicts, and custom
414417 encoded objects will be checked for circular references during encoding to
415418 prevent an infinite recursion (which would cause an :exc: `OverflowError `).
416419 Otherwise, no such check takes place.
417420
418- If *allow_nan * is `` True `` (the default), then ``NaN ``, ``Infinity ``, and
421+ If *allow_nan * is true (the default), then ``NaN ``, ``Infinity ``, and
419422 ``-Infinity `` will be encoded as such. This behavior is not JSON
420423 specification compliant, but is consistent with most JavaScript based
421424 encoders and decoders. Otherwise, it will be a :exc: `ValueError ` to encode
422425 such floats.
423426
424- If *sort_keys * is `` True `` (default ``False ``), then the output of dictionaries
427+ If *sort_keys * is true (default: ``False ``), then the output of dictionaries
425428 will be sorted by key; this is useful for regression tests to ensure that
426429 JSON serializations can be compared on a day-to-day basis.
427430
@@ -443,9 +446,10 @@ Encoders and Decoders
443446 .. versionchanged :: 3.4
444447 Use ``(',', ': ') `` as default if *indent * is not ``None ``.
445448
446- If specified, *default * is a function that gets called for objects that can't
447- otherwise be serialized. It should return a JSON encodable version of the
448- object or raise a :exc: `TypeError `.
449+ If specified, *default * should be a function that gets called for objects that
450+ can't otherwise be serialized. It should return a JSON encodable version of
451+ the object or raise a :exc: `TypeError `. If not specified, :exc: `TypeError `
452+ is raised.
449453
450454 .. versionchanged :: 3.6
451455 All parameters are now :ref: `keyword-only <keyword-only_parameter >`.
0 commit comments