diff -r aac6b313ef5f Doc/library/json.rst --- a/Doc/library/json.rst Sat Nov 24 20:42:59 2012 +0100 +++ b/Doc/library/json.rst Sun Nov 25 18:20:13 2012 +0200 @@ -94,9 +94,9 @@ .. highlight:: bash -Using json.tool from the shell to validate and pretty-print:: +Using :mod:`json.tool` from the shell to validate and pretty-print:: - $ echo '{"json":"obj"}' | python -mjson.tool + $ echo '{"json":"obj"}' | python -m json.tool { "json": "obj" } @@ -124,7 +124,7 @@ Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting :term:`file-like object`). - If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not + If *skipkeys* is true (default: ``False``), then dict keys that are not of a basic type (:class:`str`, :class:`int`, :class:`float`, :class:`bool`, ``None``) will be skipped instead of raising a :exc:`TypeError`. @@ -132,18 +132,19 @@ :class:`bytes` objects. Therefore, ``fp.write()`` must support :class:`str` input. - If *ensure_ascii* is ``True`` (the default), the output is guaranteed to + If *ensure_ascii* is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped. If *ensure_ascii* is - ``False``, these characters will be output as-is. + false, these characters will be output as-is. - If *check_circular* is ``False`` (default: ``True``), then the circular + If *check_circular* is false (default: ``True``), then the circular reference check for container types will be skipped and a circular reference will result in an :exc:`OverflowError` (or worse). - If *allow_nan* is ``False`` (default: ``True``), then it will be a + If *allow_nan* is false (default: ``True``), then it will be a :exc:`ValueError` to serialize out of range :class:`float` values (``nan``, - ``inf``, ``-inf``) in strict compliance of the JSON specification, instead of - using the JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``). + ``inf``, ``-inf``) in strict compliance of the JSON specification. + If *allow_nan* is true, their JavaScript equivalents will be used + (``NaN``, ``Infinity``, ``-Infinity``). If *indent* is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level. An indent level @@ -155,14 +156,16 @@ .. versionchanged:: 3.2 Allow strings for *indent* in addition to integers. - If *separators* is an ``(item_separator, dict_separator)`` tuple, then it - will be used instead of the default ``(', ', ': ')`` separators. ``(',', - ':')`` is the most compact JSON representation. + If specified, *separators* should be an ``(item_separator, key_separator)`` + tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON + representation, you should specify ``(',', ':')`` to eliminate whitespace. - *default(obj)* is a function that should return a serializable version of - *obj* or raise :exc:`TypeError`. The default simply raises :exc:`TypeError`. + If specified, *default* should be a function that gets called for objects that + can't otherwise be serialized. It should return a JSON encodable version of + the object or raise a :exc:`TypeError`. If not specified, :exc:`TypeError` + is always raised in those cases. - If *sort_keys* is ``True`` (default: ``False``), then the output of + If *sort_keys* is true (default: ``False``), then the output of dictionaries will be sorted by key. To use a custom :class:`JSONEncoder` subclass (e.g. one that overrides the @@ -310,7 +313,7 @@ ``'false'``. This can be used to raise an exception if invalid JSON numbers are encountered. - If *strict* is ``False`` (``True`` is the default), then control characters + If *strict* is false (``True`` is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including ``'\t'`` (tab), ``'\n'``, ``'\r'`` and ``'\0'``. @@ -360,26 +363,26 @@ for ``o`` if possible, otherwise it should call the superclass implementation (to raise :exc:`TypeError`). - If *skipkeys* is ``False`` (the default), then it is a :exc:`TypeError` to + If *skipkeys* is false (the default), then it is a :exc:`TypeError` to attempt encoding of keys that are not str, int, float or None. If - *skipkeys* is ``True``, such items are simply skipped. + *skipkeys* is true, such items are simply skipped. - If *ensure_ascii* is ``True`` (the default), the output is guaranteed to + If *ensure_ascii* is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped. If *ensure_ascii* is - ``False``, these characters will be output as-is. + false, these characters will be output as-is. - If *check_circular* is ``True`` (the default), then lists, dicts, and custom + If *check_circular* is true (the default), then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an :exc:`OverflowError`). Otherwise, no such check takes place. - If *allow_nan* is ``True`` (the default), then ``NaN``, ``Infinity``, and + If *allow_nan* is true (the default), then ``NaN``, ``Infinity``, and ``-Infinity`` will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a :exc:`ValueError` to encode such floats. - If *sort_keys* is ``True`` (default ``False``), then the output of dictionaries + If *sort_keys* is true (default: ``False``), then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis. @@ -394,12 +397,13 @@ Allow strings for *indent* in addition to integers. If specified, *separators* should be an ``(item_separator, key_separator)`` - tuple. The default is ``(', ', ': ')``. To get the most compact JSON + tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON representation, you should specify ``(',', ':')`` to eliminate whitespace. - If specified, *default* is a function that gets called for objects that can't - otherwise be serialized. It should return a JSON encodable version of the - object or raise a :exc:`TypeError`. + If specified, *default* should be a function that gets called for objects that + can't otherwise be serialized. It should return a JSON encodable version of + the object or raise a :exc:`TypeError`. If not specified, :exc:`TypeError` + is always raised in those cases. .. method:: default(o) diff -r aac6b313ef5f Lib/json/__init__.py --- a/Lib/json/__init__.py Sat Nov 24 20:42:59 2012 +0100 +++ b/Lib/json/__init__.py Sun Nov 25 18:20:13 2012 +0200 @@ -155,7 +155,7 @@ ``default(obj)`` is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError. - If *sort_keys* is ``True`` (default: ``False``), then the output of + If *sort_keys* is true (default: ``False``), then the output of dictionaries will be sorted by key. To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the @@ -216,7 +216,7 @@ ``default(obj)`` is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError. - If *sort_keys* is ``True`` (default: ``False``), then the output of + If *sort_keys* is true (default: ``False``), then the output of dictionaries will be sorted by key. To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the