summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt6
-rw-r--r--docs/_sources/index.txt22
-rw-r--r--docs/genindex.html2
-rw-r--r--docs/index.html24
-rw-r--r--docs/search.html2
-rw-r--r--docs/searchindex.json2
-rw-r--r--index.rst22
-rw-r--r--simplejson/__init__.py22
-rw-r--r--simplejson/_speedups.c8
-rw-r--r--simplejson/encoder.py20
-rw-r--r--simplejson/tests/test_indent.py44
-rw-r--r--simplejson/tests/test_separators.py2
-rw-r--r--simplejson/tool.py2
13 files changed, 105 insertions, 73 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index bea27fb..9f464f4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,10 @@
Version 2.1.0 released XXXX-XX-XX
-* Test suite (python setup.py test) now automatically runs with and without speedups
+* indent encoding parameter changed to be a string rather than an integer
+ (integer use still supported for backwards compatibility)
+ http://code.google.com/p/simplejson/issues/detail?id=56
+* Test suite (python setup.py test) now automatically runs with and without
+ speedups
http://code.google.com/p/simplejson/issues/detail?id=55
* Fixed support for older versions of easy_install (e.g. stock Mac OS X config)
http://code.google.com/p/simplejson/issues/detail?id=54
diff --git a/docs/_sources/index.txt b/docs/_sources/index.txt
index bfa3b8d..f6084bd 100644
--- a/docs/_sources/index.txt
+++ b/docs/_sources/index.txt
@@ -44,7 +44,7 @@ Compact encoding::
Pretty printing::
>>> import simplejson as json
- >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
+ >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=' ')
>>> print '\n'.join([l.rstrip() for l in s.splitlines()])
{
"4": 5,
@@ -144,10 +144,12 @@ Basic Usage
If *allow_nan* is true, their JavaScript equivalents will be used
(``NaN``, ``Infinity``, ``-Infinity``).
- If *indent* is a non-negative integer, then JSON array elements and object
- members will be pretty-printed with that indent level. An indent level of 0
- will only insert newlines. ``None`` (the default) selects the most compact
- representation.
+ If *indent* is a string, then JSON array elements and object members
+ will be pretty-printed with a newline followed by that string repeated
+ for each level of nesting. ``None`` (the default) selects the most compact
+ representation without any newlines. For backwards compatibility with
+ 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 an ``(item_separator, dict_separator)``
tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
@@ -391,10 +393,12 @@ Encoders and decoders
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.
- If *indent* is a non-negative integer (it is ``None`` by default), then JSON
- array elements and object members will be pretty-printed with that indent
- level. An indent level of 0 will only insert newlines. ``None`` is the most
- compact representation.
+ If *indent* is a string, then JSON array elements and object members
+ will be pretty-printed with a newline followed by that string repeated
+ for each level of nesting. ``None`` (the default) selects the most compact
+ representation without any newlines. For backwards compatibility with
+ 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 an ``(item_separator, key_separator)``
tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
diff --git a/docs/genindex.html b/docs/genindex.html
index a4760c3..81859b9 100644
--- a/docs/genindex.html
+++ b/docs/genindex.html
@@ -128,7 +128,7 @@
</div>
<div class="footer">
&copy; Copyright 2008, Bob Ippolito.
- Last updated on Mar 29, 2009.
+ Last updated on May 17, 2009.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
diff --git a/docs/index.html b/docs/index.html
index 7e3ea38..eca8ad7 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -72,7 +72,7 @@ extension for speedups.</p>
</pre></div>
<p>Pretty printing:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">({</span><span class="s">&#39;4&#39;</span><span class="p">:</span> <span class="mf">5</span><span class="p">,</span> <span class="s">&#39;6&#39;</span><span class="p">:</span> <span class="mf">7</span><span class="p">},</span> <span class="n">sort_keys</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mf">4</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">({</span><span class="s">&#39;4&#39;</span><span class="p">:</span> <span class="mf">5</span><span class="p">,</span> <span class="s">&#39;6&#39;</span><span class="p">:</span> <span class="mf">7</span><span class="p">},</span> <span class="n">sort_keys</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="s">&#39; &#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">l</span><span class="o">.</span><span class="n">rstrip</span><span class="p">()</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()])</span>
<span class="go">{</span>
<span class="go"> &quot;4&quot;: 5,</span>
@@ -157,10 +157,12 @@ will result in an <tt class="xref docutils literal"><span class="pre">OverflowEr
<tt class="docutils literal"><span class="pre">inf</span></tt>, <tt class="docutils literal"><span class="pre">-inf</span></tt>) in strict compliance of the JSON specification.
If <em>allow_nan</em> is true, their JavaScript equivalents will be used
(<tt class="docutils literal"><span class="pre">NaN</span></tt>, <tt class="docutils literal"><span class="pre">Infinity</span></tt>, <tt class="docutils literal"><span class="pre">-Infinity</span></tt>).</p>
-<p>If <em>indent</em> is a non-negative integer, then JSON array elements and object
-members will be pretty-printed with that indent level. An indent level of 0
-will only insert newlines. <tt class="xref docutils literal"><span class="pre">None</span></tt> (the default) selects the most compact
-representation.</p>
+<p>If <em>indent</em> is a string, then JSON array elements and object members
+will be pretty-printed with a newline followed by that string repeated
+for each level of nesting. <tt class="xref docutils literal"><span class="pre">None</span></tt> (the default) selects the most compact
+representation without any newlines. For backwards compatibility with
+versions of simplejson earlier than 2.1.0, an integer is also accepted
+and is converted to a string with that many spaces.</p>
<p>If specified, <em>separators</em> should be an <tt class="docutils literal"><span class="pre">(item_separator,</span> <span class="pre">dict_separator)</span></tt>
tuple. By default, <tt class="docutils literal"><span class="pre">(',</span> <span class="pre">',</span> <span class="pre">':</span> <span class="pre">')</span></tt> are used. To get the most compact JSON
representation, you should specify <tt class="docutils literal"><span class="pre">(',',</span> <span class="pre">':')</span></tt> to eliminate whitespace.</p>
@@ -414,10 +416,12 @@ such floats.</p>
<p>If <em>sort_keys</em> is true (the default), 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.</p>
-<p>If <em>indent</em> is a non-negative integer (it is <tt class="xref docutils literal"><span class="pre">None</span></tt> by default), then JSON
-array elements and object members will be pretty-printed with that indent
-level. An indent level of 0 will only insert newlines. <tt class="xref docutils literal"><span class="pre">None</span></tt> is the most
-compact representation.</p>
+<p>If <em>indent</em> is a string, then JSON array elements and object members
+will be pretty-printed with a newline followed by that string repeated
+for each level of nesting. <tt class="xref docutils literal"><span class="pre">None</span></tt> (the default) selects the most compact
+representation without any newlines. For backwards compatibility with
+versions of simplejson earlier than 2.1.0, an integer is also accepted
+and is converted to a string with that many spaces.</p>
<p>If specified, <em>separators</em> should be an <tt class="docutils literal"><span class="pre">(item_separator,</span> <span class="pre">key_separator)</span></tt>
tuple. By default, <tt class="docutils literal"><span class="pre">(',</span> <span class="pre">',</span> <span class="pre">':</span> <span class="pre">')</span></tt> are used. To get the most compact JSON
representation, you should specify <tt class="docutils literal"><span class="pre">(',',</span> <span class="pre">':')</span></tt> to eliminate whitespace.</p>
@@ -514,7 +518,7 @@ available. For example:</p>
</div>
<div class="footer">
&copy; Copyright 2008, Bob Ippolito.
- Last updated on Mar 29, 2009.
+ Last updated on May 17, 2009.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
diff --git a/docs/search.html b/docs/search.html
index 408645a..655698b 100644
--- a/docs/search.html
+++ b/docs/search.html
@@ -74,7 +74,7 @@
</div>
<div class="footer">
&copy; Copyright 2008, Bob Ippolito.
- Last updated on Mar 29, 2009.
+ Last updated on May 17, 2009.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
diff --git a/docs/searchindex.json b/docs/searchindex.json
index ea16595..93605d1 100644
--- a/docs/searchindex.json
+++ b/docs/searchindex.json
@@ -1 +1 @@
-[["index"],["<tt class=\"docutils literal\"><span class=\"pre\">simplejson</span></tt> &#8212; JSON encoder and decoder"],{"represent":[0],"all":[0],"skip":[0],"interchang":[0],"signific":[0],"follow":[0],"compact":[0],"typeerror":[0],"tt":[0],"decim":[0],"0":[0],"rstrip":[0],"sens":[0],"spec":[0],"isinst":[0],"liter":[0],"everi":[0],"string":[0],"raw_decod":[0],"fals":[0],"jsonencod":[0],"level":[0],"list":[0],"iter":[0],"try":[0],"item":[0],"prevent":[0],"pass":[0],"compat":[0],"index":[0],"compar":[0],"neg":[0],"current":[0],"version":[0],"method":[0],"item_separ":[0],"elimin":[0],"valu":[0],"num_str":[0],"produc":[0],"prior":[0],"implement":[0],"control":[0],"modul":[0],"api":[0],"coercion":[0],"select":[0],"highli":[0],"from":[0],"would":[0],"to":[0],"call":[0],"6":[0],"type":[0],"more":[0],"sort":[0],"unescap":[0],"it":[0],"must":[0],"none":[0],"join":[0],"bigobject":[0],"work":[0],"skipkei":[0],"wors":[0],"can":[0],"def":[0],"overrid":[0],"stream":[0],"lightweight":[0],"serial":[0],"object_pairs_hook":[0],"alwai":[0],"end":[0],"newlin":[0],"anoth":[0],"1":[0],"instead":[0],"simpl":[0],"circular":[0],"fp":[0],"recogn":[0],"after":[0],"mai":[0],"such":[0],"data":[0],"a":[0],"attempt":[0],"correspond":[0],"marshal":[0],"caus":[0],"maintain":[0],"so":[0],"allow":[0],"order":[0],"becaus":[0],"hierarchi":[0],"write":[0],"better":[0],"yaml":[0],"then":[0],"them":[0],"return":[0],"thei":[0],"python":[0],"safe":[0],"dai":[0],"not":[0],"jsondecod":[0],"superset":[0],"name":[0],"anyth":[0],"edit":[0],"l":[0],"separ":[0],"getvalu":[0],"each":[0],"unicod":[0],"2j":[0],"mean":[0],"subset":[0],"chunk":[0],"ensur":[0],"expect":[0],"special":[0],"out":[0],"3rd":[0],"content":[0],"7":[0],"print":[0],"infin":[0],"standard":[0],"base":[0],"dictionari":[0],"element":[0],"org":[0],"basi":[0],"indent":[0],"g":[0],"could":[0],"place":[0],"outsid":[0],"regress":[0],"first":[0],"rang":[0],"arrai":[0],"number":[0],"echo":[0],"unlik":[0],"prioriti":[0],"given":[0],"reli":[0],"their":[0],"2":[0],"1j":[0],"shell":[0],"option":[0],"that":[0],"tool":[0],"specifi":[0],"pars":[0],"than":[0],"b":[0],"keyword":[0],"whenev":[0],"provid":[0],"structur":[0],"charact":[0],"r":[],"str":[0],"pre":[0],"encode_complex":[0],"argument":[0],"have":[0],"null":[0],"equival":[0],"self":[0],"note":[0],"also":[0],"without":[0],"take":[0],"which":[0],"even":[0],"begin":[0],"unless":[0],"normal":[0],"object":[0],"most":[0],"getread":[0],"pair":[0],"class":[0],"m":[0],"doe":[0],"kw":[0],"determin":[0],"serializ":[0],"speedup":[0],"syntax":[0],"find":[0],"onli":[0],"explicitli":[0],"parse_float":[0],"pretti":[0],"with":[0],"3":[0],"should":[0],"iterencod":[0],"dict":[0],"8":[0],"object_hook":[0],"get":[0],"familiar":[0],"stop":[0],"repr":[0],"fastest":[0],"key_separ":[0],"bar":[0],"baz":[0],"yield":[0],"contain":[0],"where":[0],"valid":[0],"set":[0],"dump":[0],"frame":[0],"datatyp":[0],"result":[0],"best":[0],"subject":[0],"infinit":[0],"extend":[0],"dict_separ":[0],"written":[0],"import":[0],"latin":[0],"kei":[0],"parse_const":[0],"javascript":[0],"extens":[0],"addit":[0],"c":[0],"delimit":[0],"s":[0],"instanc":[0],"ecma":[0],"load":[0],"and":[0],"simpli":[0],"cl":[0],"8212":[0],"rpc":[0],"getwrit":[0],"__complex__":[0],"json":[0],"much":[0],"interpret":[0],"basic":[0],"valueerror":[0],"imag":[0],"ani":[0],"understand":[0],"func":[],"input":[0],"sort_kei":[0],"those":[0],"case":[0],"x08ar":[0],"properti":[0],"n":[0],"will":[0],"defin":[0],"behavior":[0],"error":[0],"ordereddict":[0],"advantag":[0],"is":[0],"non":[0],"kwarg":[0],"io":[0],"in":[0],"incom":[0],"ascii":[0],"if":[0],"u1234":[0],"perform":[0],"make":[0],"same":[0],"member":[0],"complex":[0],"decod":[0],"document":[0],"http":[0],"optim":[0],"effect":[0],"rais":[0],"user":[0],"extern":[0],"appropri":[0],"well":[0],"pickl":[0],"exampl":[0],"thi":[0],"the":[0],"protocol":[0],"mysocket":[0],"rest":[0],"allow_nan":[0],"as_complex":[0],"parse_int":[0],"expos":[0],"hint":[0],"except":[0],"other":[0],"4":[0],"els":[0],"real":[0],"msimplejson":[],"format":[0],"read":[0],"262":[0],"recurs":[0],"insert":[0],"like":[0],"specif":[0],"arbitrari":[0],"docutil":[0],"whitespac":[0],"integ":[0],"collect":[0],"t":[0],"output":[0],"encount":[0],"some":[0],"check_circular":[0],"superclass":[0],"guarante":[0],"5":[0],"librari":[0],"for":[0],"subclass":[0],"when":[0],"leav":[0],"foo":[0],"refer":[0],"be":[0],"usag":[0],"dct":[0],"by":[0],"on":[0],"obj":[0],"column":[0],"of":[0],"o":[0],"splitlin":[0],"constructor":[0],"or":[0],"into":[0],"float":[0],"encod":[0],"wrap":[0],"span":[0],"complianc":[0],"support":[0],"there":[0],"transform":[0],"long":[0],"custom":[0],"avail":[0],"strict":[0],"compliant":[0],"overflowerror":[0],"function":[0],"simplejson":[0],"tupl":[0],"recommend":[0],"but":[0],"translat":[0],"line":[0],"ha":[0],"true":[0],"notat":[0],"utf":[0],"consist":[0],"possibl":[0],"default":[0],"us":[0],"otherwis":[0],"ensure_ascii":[0],"uc":[0],"featur":[0],"ad":[0],"int":[0],"dure":[0],"parser":[0],"an":[0],"char":[0],"as":[0],"ar":[0],"at":[0],"file":[0],"inf":[0],"check":[0],"no":[0],"complexencod":[],"nan":[0],"invalid":[0],"codec":[0],"bool":[0],"rememb":[0],"test":[0],"you":[0],"deseri":[0],"stringio":[0],"e":[0],"extran":[0],"rule":[0],"u":[0],"escap":[0]}] \ No newline at end of file
+[["index"],["<tt class=\"docutils literal\"><span class=\"pre\">simplejson</span></tt> &#8212; JSON encoder and decoder"],{"represent":[0],"all":[0],"skip":[0],"interchang":[0],"signific":[0],"follow":[0],"compact":[0],"typeerror":[0],"tt":[0],"decim":[0],"0":[0],"rstrip":[0],"sens":[0],"spec":[0],"isinst":[0],"liter":[0],"everi":[0],"string":[0],"raw_decod":[0],"fals":[0],"jsonencod":[0],"level":[0],"list":[0],"iter":[0],"try":[0],"item":[0],"prevent":[0],"pass":[0],"compat":[0],"index":[0],"compar":[0],"neg":[],"current":[0],"version":[0],"method":[0],"item_separ":[0],"elimin":[0],"valu":[0],"num_str":[0],"convert":[0],"prior":[0],"implement":[0],"control":[0],"modul":[0],"api":[0],"coercion":[0],"select":[0],"highli":[0],"or":[0],"from":[0],"would":[0],"to":[0],"call":[0],"6":[0],"type":[0],"more":[0],"sort":[0],"unescap":[0],"it":[0],"must":[0],"none":[0],"join":[0],"bigobject":[0],"work":[0],"skipkei":[0],"wors":[0],"can":[0],"def":[0],"overrid":[0],"stream":[0],"lightweight":[0],"accept":[0],"serial":[0],"object_pairs_hook":[0],"alwai":[0],"end":[0],"newlin":[0],"anoth":[0],"write":[0],"instead":[0],"simpl":[0],"circular":[0],"fp":[0],"recogn":[0],"earlier":[0],"mai":[0],"such":[0],"data":[0],"a":[0],"attempt":[0],"correspond":[0],"element":[0],"caus":[0],"maintain":[0],"so":[0],"allow":[0],"order":[0],"becaus":[0],"hierarchi":[0],"1":[0],"better":[0],"yaml":[0],"then":[0],"them":[0],"return":[0],"thei":[0],"python":[0],"safe":[0],"dai":[0],"allow_nan":[0],"jsondecod":[0],"superset":[0],"name":[0],"anyth":[0],"edit":[0],"l":[0],"separ":[0],"getvalu":[0],"each":[0],"unicod":[0],"2j":[0],"mean":[0],"subset":[0],"chunk":[0],"wrap":[0],"expect":[0],"special":[0],"out":[0],"3rd":[0],"space":[0],"content":[0],"7":[0],"print":[0],"after":[0],"infin":[0],"standard":[0],"base":[0],"dictionari":[0],"org":[0],"basi":[0],"indent":[0],"g":[0],"rule":[0],"could":[0],"place":[0],"outsid":[0],"regress":[0],"first":[0],"rang":[0],"arrai":[0],"number":[0],"echo":[0],"unlik":[0],"prioriti":[0],"given":[0],"compliant":[0],"their":[0],"2":[0],"1j":[0],"shell":[0],"option":[0],"that":[0],"tool":[0],"specifi":[0],"pars":[0],"than":[0],"b":[0],"keyword":[0],"whenev":[0],"provid":[0],"structur":[0],"charact":[0],"r":[],"str":[0],"pre":[0],"encode_complex":[0],"ani":[0],"have":[0],"null":[0],"equival":[0],"self":[0],"note":[0],"also":[0],"without":[0],"take":[0],"which":[0],"codec":[0],"even":[0],"begin":[0],"unless":[0],"normal":[0],"object":[0],"most":[0],"getread":[0],"pair":[0],"class":[0],"marshal":[0],"nan":[0],"m":[0],"doe":[0],"kw":[0],"determin":[0],"serializ":[0],"speedup":[0],"syntax":[0],"find":[0],"onli":[0],"explicitli":[0],"parse_float":[0],"pretti":[0],"true":[0],"3":[0],"should":[0],"iterencod":[0],"dict":[0],"8":[0],"object_hook":[0],"get":[0],"familiar":[0],"stop":[0],"repr":[0],"fastest":[0],"key_separ":[0],"bar":[0],"baz":[0],"yield":[0],"contain":[0],"where":[0],"set":[0],"dump":[0],"frame":[0],"datatyp":[0],"result":[0],"best":[0],"subject":[0],"infinit":[0],"extend":[0],"dict_separ":[0],"written":[0],"import":[0],"latin":[0],"kei":[0],"parse_const":[0],"javascript":[0],"extens":[0],"addit":[0],"c":[0],"delimit":[0],"s":[0],"instanc":[0],"mani":[0],"ecma":[0],"load":[0],"and":[0],"simpli":[0],"cl":[0],"8212":[0],"rpc":[0],"getwrit":[0],"__complex__":[0],"json":[0],"much":[0],"interpret":[0],"basic":[0],"valueerror":[0],"imag":[0],"argument":[0],"understand":[0],"func":[],"input":[0],"sort_kei":[0],"those":[0],"case":[0],"x08ar":[0],"properti":[0],"n":[0],"will":[0],"defin":[0],"behavior":[0],"error":[0],"ordereddict":[0],"advantag":[0],"is":[0],"non":[],"kwarg":[0],"io":[0],"in":[0],"incom":[0],"ascii":[0],"if":[0],"u1234":[0],"perform":[0],"make":[0],"same":[0],"member":[0],"complex":[0],"decod":[0],"document":[0],"http":[0],"optim":[0],"nest":[0],"effect":[0],"rais":[0],"user":[0],"extern":[0],"appropri":[0],"well":[0],"pickl":[0],"exampl":[0],"thi":[0],"the":[0],"protocol":[0],"mysocket":[0],"rest":[0],"not":[0],"as_complex":[0],"parse_int":[0],"expos":[0],"hint":[0],"except":[0],"other":[0],"4":[0],"els":[0],"real":[0],"msimplejson":[],"format":[0],"read":[0],"262":[0],"recurs":[0],"insert":[0],"like":[0],"specif":[0],"arbitrari":[0],"docutil":[0],"whitespac":[0],"integ":[0],"collect":[0],"t":[0],"output":[0],"encount":[0],"some":[0],"check_circular":[0],"superclass":[0],"guarante":[0],"librari":[0],"for":[0],"subclass":[0],"leav":[0],"foo":[0],"refer":[0],"be":[0],"usag":[0],"dct":[0],"by":[0],"on":[0],"obj":[0],"column":[0],"of":[0],"o":[0],"splitlin":[0],"constructor":[0],"produc":[0],"into":[0],"float":[0],"encod":[0],"ensur":[0],"bool":[0],"span":[0],"complianc":[0],"support":[0],"there":[0],"transform":[0],"long":[0],"custom":[0],"avail":[0],"strict":[0],"reli":[0],"overflowerror":[0],"function":[0],"simplejson":[0],"tupl":[0],"recommend":[0],"but":[0],"translat":[0],"line":[0],"ha":[0],"with":[0],"notat":[0],"utf":[0],"consist":[0],"possibl":[0],"default":[0],"us":[0],"otherwis":[0],"ensure_ascii":[0],"uc":[0],"featur":[0],"ad":[0],"int":[0],"dure":[0],"parser":[0],"an":[0],"char":[0],"as":[0],"ar":[0],"at":[0],"file":[0],"inf":[0],"check":[0],"no":[0],"complexencod":[],"when":[0],"invalid":[0],"valid":[0],"5":[0],"rememb":[0],"test":[0],"you":[0],"deseri":[0],"repeat":[0],"stringio":[0],"e":[0],"extran":[0],"u":[0],"escap":[0],"backward":[0]}] \ No newline at end of file
diff --git a/index.rst b/index.rst
index bfa3b8d..f6084bd 100644
--- a/index.rst
+++ b/index.rst
@@ -44,7 +44,7 @@ Compact encoding::
Pretty printing::
>>> import simplejson as json
- >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
+ >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=' ')
>>> print '\n'.join([l.rstrip() for l in s.splitlines()])
{
"4": 5,
@@ -144,10 +144,12 @@ Basic Usage
If *allow_nan* is true, their JavaScript equivalents will be used
(``NaN``, ``Infinity``, ``-Infinity``).
- If *indent* is a non-negative integer, then JSON array elements and object
- members will be pretty-printed with that indent level. An indent level of 0
- will only insert newlines. ``None`` (the default) selects the most compact
- representation.
+ If *indent* is a string, then JSON array elements and object members
+ will be pretty-printed with a newline followed by that string repeated
+ for each level of nesting. ``None`` (the default) selects the most compact
+ representation without any newlines. For backwards compatibility with
+ 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 an ``(item_separator, dict_separator)``
tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
@@ -391,10 +393,12 @@ Encoders and decoders
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.
- If *indent* is a non-negative integer (it is ``None`` by default), then JSON
- array elements and object members will be pretty-printed with that indent
- level. An indent level of 0 will only insert newlines. ``None`` is the most
- compact representation.
+ If *indent* is a string, then JSON array elements and object members
+ will be pretty-printed with a newline followed by that string repeated
+ for each level of nesting. ``None`` (the default) selects the most compact
+ representation without any newlines. For backwards compatibility with
+ 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 an ``(item_separator, key_separator)``
tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index 4104035..7020140 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -37,7 +37,7 @@ Compact encoding::
Pretty printing::
>>> import simplejson as json
- >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
+ >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=' ')
>>> print '\n'.join([l.rstrip() for l in s.splitlines()])
{
"4": 5,
@@ -149,10 +149,12 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
in strict compliance of the JSON specification, instead of using the
JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
- If ``indent`` is a non-negative integer, then JSON array elements and
- object members will be pretty-printed with that indent level. An indent
- level of 0 will only insert newlines. ``None`` is the most compact
- representation.
+ If *indent* is a string, then JSON array elements and object members
+ will be pretty-printed with a newline followed by that string repeated
+ for each level of nesting. ``None`` (the default) selects the most compact
+ representation without any newlines. For backwards compatibility with
+ 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.
@@ -209,10 +211,12 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
strict compliance of the JSON specification, instead of using the
JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
- If ``indent`` is a non-negative integer, then JSON array elements and
- object members will be pretty-printed with that indent level. An indent
- level of 0 will only insert newlines. ``None`` is the most compact
- representation.
+ If ``indent`` is a string, then JSON array elements and object members
+ will be pretty-printed with a newline followed by that string repeated
+ for each level of nesting. ``None`` (the default) selects the most compact
+ representation without any newlines. For backwards compatibility with
+ 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.
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
index 57ab6b0..3584c60 100644
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -2102,7 +2102,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
/* TODO: DOES NOT RUN */
indent_level += 1;
/*
- newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ newline_indent = '\n' + (_indent * _current_indent_level)
separator = _item_separator + newline_indent
buf += newline_indent
*/
@@ -2173,7 +2173,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
/* TODO: DOES NOT RUN */
indent_level -= 1;
/*
- yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield '\n' + (_indent * _current_indent_level)
*/
}
if (PyList_Append(rval, close_dict))
@@ -2240,7 +2240,7 @@ encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ss
/* TODO: DOES NOT RUN */
indent_level += 1;
/*
- newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ newline_indent = '\n' + (_indent * _current_indent_level)
separator = _item_separator + newline_indent
buf += newline_indent
*/
@@ -2263,7 +2263,7 @@ encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ss
/* TODO: DOES NOT RUN */
indent_level -= 1;
/*
- yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield '\n' + (_indent * _current_indent_level)
*/
}
if (PyList_Append(rval, close_array))
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index fd46eb4..31c3023 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -129,10 +129,12 @@ class JSONEncoder(object):
sorted by key; this is useful for regression tests to ensure
that JSON serializations can be compared on a day-to-day basis.
- If indent is a non-negative integer, then JSON array
- elements and object members will be pretty-printed with that
- indent level. An indent level of 0 will only insert newlines.
- None is the most compact representation.
+ If indent is a string, then JSON array elements and object members
+ will be pretty-printed with a newline followed by that string repeated
+ for each level of nesting. ``None`` (the default) selects the most compact
+ representation without any newlines. For backwards compatibility with
+ 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
@@ -153,6 +155,8 @@ class JSONEncoder(object):
self.check_circular = check_circular
self.allow_nan = allow_nan
self.sort_keys = sort_keys
+ if isinstance(indent, (int, long)):
+ indent = ' ' * indent
self.indent = indent
if separators is not None:
self.item_separator, self.key_separator = separators
@@ -300,7 +304,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
buf = '['
if _indent is not None:
_current_indent_level += 1
- newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ newline_indent = '\n' + (_indent * _current_indent_level)
separator = _item_separator + newline_indent
buf += newline_indent
else:
@@ -336,7 +340,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
yield chunk
if newline_indent is not None:
_current_indent_level -= 1
- yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield '\n' + (_indent * _current_indent_level)
yield ']'
if markers is not None:
del markers[markerid]
@@ -353,7 +357,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
yield '{'
if _indent is not None:
_current_indent_level += 1
- newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ newline_indent = '\n' + (_indent * _current_indent_level)
item_separator = _item_separator + newline_indent
yield newline_indent
else:
@@ -413,7 +417,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
yield chunk
if newline_indent is not None:
_current_indent_level -= 1
- yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield '\n' + (_indent * _current_indent_level)
yield '}'
if markers is not None:
del markers[markerid]
diff --git a/simplejson/tests/test_indent.py b/simplejson/tests/test_indent.py
index 66e19b9..fa07075 100644
--- a/simplejson/tests/test_indent.py
+++ b/simplejson/tests/test_indent.py
@@ -10,32 +10,40 @@ class TestIndent(TestCase):
expect = textwrap.dedent("""\
[
- [
- "blorpie"
- ],
- [
- "whoops"
- ],
- [],
- "d-shtaeou",
- "d-nthiouh",
- "i-vhbjkhnth",
- {
- "nifty": 87
- },
- {
- "field": "yes",
- "morefield": false
- }
+ \t[
+ \t\t"blorpie"
+ \t],
+ \t[
+ \t\t"whoops"
+ \t],
+ \t[],
+ \t"d-shtaeou",
+ \t"d-nthiouh",
+ \t"i-vhbjkhnth",
+ \t{
+ \t\t"nifty": 87
+ \t},
+ \t{
+ \t\t"field": "yes",
+ \t\t"morefield": false
+ \t}
]""")
d1 = json.dumps(h)
- d2 = json.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
+ d2 = json.dumps(h, indent='\t', sort_keys=True, separators=(',', ': '))
+ d3 = json.dumps(h, indent=' ', sort_keys=True, separators=(',', ': '))
+ d4 = json.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
h1 = json.loads(d1)
h2 = json.loads(d2)
+ h3 = json.loads(d3)
+ h4 = json.loads(d4)
self.assertEquals(h1, h)
self.assertEquals(h2, h)
+ self.assertEquals(h3, h)
+ self.assertEquals(h4, h)
self.assertEquals(d2, expect)
+ self.assertEquals(d3, expect.replace('\t', ' '))
+ self.assertEquals(d4, expect.replace('\t', ' '))
diff --git a/simplejson/tests/test_separators.py b/simplejson/tests/test_separators.py
index 8fa0dac..cbda93c 100644
--- a/simplejson/tests/test_separators.py
+++ b/simplejson/tests/test_separators.py
@@ -32,7 +32,7 @@ class TestSeparators(TestCase):
d1 = json.dumps(h)
- d2 = json.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))
+ d2 = json.dumps(h, indent=' ', sort_keys=True, separators=(' ,', ' : '))
h1 = json.loads(d1)
h2 = json.loads(d2)
diff --git a/simplejson/tool.py b/simplejson/tool.py
index b3d47ed..629dca4 100644
--- a/simplejson/tool.py
+++ b/simplejson/tool.py
@@ -29,7 +29,7 @@ def main():
obj = json.load(infile, object_pairs_hook=json.OrderedDict)
except ValueError, e:
raise SystemExit(e)
- json.dump(obj, outfile, sort_keys=True, indent=4)
+ json.dump(obj, outfile, sort_keys=True, indent=' ')
outfile.write('\n')