Skip to content

Instantly share code, notes, and snippets.

@serhiy-storchaka
Created February 22, 2013 19:19
Show Gist options
  • Save serhiy-storchaka/5015859 to your computer and use it in GitHub Desktop.
Save serhiy-storchaka/5015859 to your computer and use it in GitHub Desktop.
diff --git a/index.rst b/index.rst
index f1ae6a9..f682fd6 100644
--- a/index.rst
+++ b/index.rst
@@ -48,8 +48,7 @@ Compact encoding::
Pretty printing::
>>> import simplejson as json
- >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4 * ' ')
- >>> print('\n'.join([l.rstrip() for l in s.splitlines()]))
+ >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4 * ' '))
{
"4": 5,
"6": 7
@@ -167,9 +166,13 @@ Basic Usage
.. versionchanged:: 2.1.0
Changed *indent* from an integer number of spaces to a string.
- If specified, *separators* should be an ``(item_separator, dict_separator)``
- tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
- representation, you should specify ``(',', ':')`` to eliminate whitespace.
+ If specified, *separators* should be an ``(item_separator, key_separator)``
+ tuple. The default is ``(', ', ': ')`` if *indent* is ``None`` and
+ ``(',', ': ')`` otherwise. To get the most compact JSON representation,
+ you should specify ``(',', ':')`` to eliminate whitespace.
+
+ .. versionchanged:: 2.1.4
+ Use ``(',', ': ')`` as default if *indent* is not ``None``.
*encoding* is the character encoding for str instances, default is
``'utf-8'``.
@@ -527,8 +530,14 @@ Encoders and decoders
Changed *indent* from an integer number of spaces to a string.
If specified, *separators* should be an ``(item_separator, key_separator)``
- tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
+ tuple. The default is ``(', ', ': ')``. To get the most compact JSON
representation, you should specify ``(',', ':')`` to eliminate whitespace.
+ tuple. The default is ``(', ', ': ')`` if *indent* is ``None`` and
+ ``(',', ': ')`` otherwise. To get the most compact JSON representation,
+ you should specify ``(',', ':')`` to eliminate whitespace.
+
+ .. versionchanged:: 2.1.4
+ Use ``(',', ': ')`` as default if *indent* is not ``None``.
If specified, *default* should be a function that gets called for objects
that can't otherwise be serialized. It should return a JSON encodable
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index 9825a97..9a5d114 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -38,8 +38,7 @@ Compact encoding::
Pretty printing::
>>> import simplejson as json
- >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=' ')
- >>> print('\n'.join([l.rstrip() for l in s.splitlines()]))
+ >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=' '))
{
"4": 5,
"6": 7
@@ -180,9 +179,10 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
versions of simplejson earlier than 2.1.0, an integer is also accepted
and is converted to a string with that many spaces.
- 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. The default is ``(', ', ': ')`` if *indent* is ``None`` and
+ ``(',', ': ')`` otherwise. To get the most compact JSON representation,
+ you should specify ``(',', ':')`` to eliminate whitespace.
``encoding`` is the character encoding for str instances, default is UTF-8.
@@ -277,9 +277,10 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
versions of simplejson earlier than 2.1.0, an integer is also accepted
and is converted to a string with that many spaces.
- 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. The default is ``(', ', ': ')`` if *indent* is ``None`` and
+ ``(',', ': ')`` otherwise. To get the most compact JSON representation,
+ you should specify ``(',', ':')`` to eliminate whitespace.
``encoding`` is the character encoding for str instances, default is UTF-8.
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index db5c946..213fefb 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -153,9 +153,10 @@ class JSONEncoder(object):
versions of simplejson earlier than 2.1.0, an integer is also accepted
and is converted to a string with that many spaces.
- If specified, separators should be a (item_separator, key_separator)
- tuple. The default is (', ', ': '). To get the most compact JSON
- representation you should specify (',', ':') to eliminate whitespace.
+ If specified, separators should be an (item_separator, key_separator)
+ tuple. The default is (', ', ': ') if *indent* is ``None`` and
+ (',', ': ') otherwise. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment