diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 69ebc4f..3224bb9 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -127,11 +127,12 @@ Basic Usage :class:`float`, :class:`bool`, ``None``) will be skipped instead of raising a :exc:`TypeError`. - If *ensure_ascii* is ``False`` (default: ``True``), then some chunks written - to *fp* may be :class:`unicode` instances, subject to normal Python - :class:`str` to :class:`unicode` coercion rules. Unless ``fp.write()`` - explicitly understands :class:`unicode` (as in :func:`codecs.getwriter`) this - is likely to cause an error. + If *ensure_ascii* is ``False`` (default: ``True``), non-ASCII characters are + not escaped, and some chunks written to *fp* may be :class:`unicode` + instances, subject to normal Python :class:`str` to :class:`unicode` + coercion rules. Unless ``fp.write()`` explicitly understands + :class:`unicode` (as in :func:`codecs.getwriter`) this is likely to cause an + error. If *check_circular* is ``False`` (default: ``True``), then the circular reference check for container types will be skipped and a circular reference @@ -168,11 +169,11 @@ Basic Usage .. function:: dumps(obj[, skipkeys[, ensure_ascii[, check_circular[, allow_nan[, cls[, indent[, separators[, encoding[, default[, **kw]]]]]]]]]]) - Serialize *obj* to a JSON formatted :class:`str`. + Serialize *obj* to a JSON formatted :class:`str`. If *ensure_ascii* is + ``False``, the return value may be a :class:`unicode` instance, subject to + normal Python :class:`str` to :class:`unicode` coercion rules. - If *ensure_ascii* is ``False``, then the return value will be a - :class:`unicode` instance. The other arguments have the same meaning as in - :func:`dump`. + The arguments have the same meaning as in :func:`dump`. .. note:: @@ -372,8 +373,8 @@ Encoders and Decoders *skipkeys* is ``True``, such items are simply skipped. If *ensure_ascii* is ``True`` (the default), the output is guaranteed to be - :class:`str` objects with all incoming unicode characters escaped. If - *ensure_ascii* is ``False``, the output will be a unicode object. + :class:`str` objects with all incoming non-ASCII characters escaped. If + *ensure_ascii* is ``False``, the output may also be :class:`unicode`. If *check_circular* is ``True`` (the default), then lists, dicts, and custom encoded objects will be checked for circular references during encoding to diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py index d3b8b0b..51c69f4 100644 --- a/Lib/json/__init__.py +++ b/Lib/json/__init__.py @@ -129,11 +129,11 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``TypeError``. - If ``ensure_ascii`` is false, then the some chunks written to ``fp`` - may be ``unicode`` instances, subject to normal Python ``str`` to - ``unicode`` coercion rules. Unless ``fp.write()`` explicitly - understands ``unicode`` (as in ``codecs.getwriter()``) this is likely - to cause an error. + If ``ensure_ascii`` is false, non-ASCII characters are not escaped, and + some chunks written to ``fp`` may be ``unicode`` instances, subject to + normal Python ``str`` to ``unicode`` coercion rules. Unless ``fp.write()`` + explicitly understands ``unicode`` (as in ``codecs.getwriter()``) this is + likely to cause an error. If ``check_circular`` is false, then the circular reference check for container types will be skipped and a circular reference will @@ -191,9 +191,8 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``TypeError``. - If ``ensure_ascii`` is false, then the return value will be a - ``unicode`` instance subject to normal Python ``str`` to ``unicode`` - coercion rules instead of being escaped to an ASCII ``str``. + If ``ensure_ascii`` is false, all non-ASCII characters are not escaped, and + the return value may be a ``unicode`` instance. If ``check_circular`` is false, then the circular reference check for container types will be skipped and a circular reference will diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py index b0d745b..001945a 100644 --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -108,8 +108,8 @@ class JSONEncoder(object): skipkeys is True, such items are simply skipped. If ensure_ascii is true, the output is guaranteed to be str - objects with all incoming unicode characters escaped. If - ensure_ascii is false, the output will be unicode object. + objects with all incoming non-ASCII characters escaped. If + ensure_ascii is false, the output may also be unicode objects. If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to