index.html 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>simplejson &#8212; JSON encoder and decoder &mdash; simplejson v2.0.0 documentation</title>
  6. <link rel="stylesheet" href="_static/default.css" type="text/css" />
  7. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  8. <script type="text/javascript">
  9. var DOCUMENTATION_OPTIONS = {
  10. URL_ROOT: '',
  11. VERSION: '2.0.0',
  12. COLLAPSE_MODINDEX: false,
  13. FILE_SUFFIX: '.html'
  14. };
  15. </script>
  16. <script type="text/javascript" src="_static/jquery.js"></script>
  17. <script type="text/javascript" src="_static/interface.js"></script>
  18. <script type="text/javascript" src="_static/doctools.js"></script>
  19. <link rel="contents" title="Global table of contents" href="contents.html" />
  20. <link rel="index" title="Global index" href="genindex.html" />
  21. <link rel="search" title="Search" href="search.html" />
  22. <link rel="top" title="simplejson v2.0.0 documentation" href="" />
  23. </head>
  24. <body>
  25. <div class="related">
  26. <h3>Navigation</h3>
  27. <ul>
  28. <li class="right" style="margin-right: 10px">
  29. <a href="genindex.html" title="General Index"
  30. accesskey="I">index</a></li>
  31. <li><a href="">simplejson v2.0.0 documentation</a> &raquo;</li>
  32. </ul>
  33. </div>
  34. <div class="document">
  35. <div class="documentwrapper">
  36. <div class="bodywrapper">
  37. <div class="body">
  38. <div class="section" id="module-simplejson">
  39. <h1 id="module-simplejson"><tt class="xref docutils literal"><span class="pre">simplejson</span></tt> &#8212; JSON encoder and decoder<a class="headerlink" href="#module-simplejson" title="Permalink to this headline">¶</a></h1>
  40. <p>JSON (JavaScript Object Notation) &lt;<a class="reference external" href="http://json.org">http://json.org</a>&gt; is a subset of JavaScript
  41. syntax (ECMA-262 3rd edition) used as a lightweight data interchange format.</p>
  42. <p><tt class="xref docutils literal"><span class="pre">simplejson</span></tt> exposes an API familiar to users of the standard library
  43. <tt class="xref docutils literal"><span class="pre">marshal</span></tt> and <tt class="xref docutils literal"><span class="pre">pickle</span></tt> modules. It is the externally maintained
  44. version of the <tt class="xref docutils literal"><span class="pre">json</span></tt> library contained in Python 2.6, but maintains
  45. compatibility with Python 2.4 and Python 2.5 and (currently) has
  46. significant performance advantages, even without using the optional C
  47. extension for speedups.</p>
  48. <p>Encoding basic Python object hierarchies:</p>
  49. <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>
  50. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">([</span><span class="s">&#39;foo&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;bar&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;baz&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">2</span><span class="p">)}])</span>
  51. <span class="go">&#39;[&quot;foo&quot;, {&quot;bar&quot;: [&quot;baz&quot;, null, 1.0, 2]}]&#39;</span>
  52. <span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\&quot;</span><span class="s">foo</span><span class="se">\b</span><span class="s">ar&quot;</span><span class="p">)</span>
  53. <span class="go">&quot;\&quot;foo\bar&quot;</span>
  54. <span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="s">u&#39;</span><span class="se">\u1234</span><span class="s">&#39;</span><span class="p">)</span>
  55. <span class="go">&quot;\u1234&quot;</span>
  56. <span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\\</span><span class="s">&#39;</span><span class="p">)</span>
  57. <span class="go">&quot;\\&quot;</span>
  58. <span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">({</span><span class="s">&quot;c&quot;</span><span class="p">:</span> <span class="mf">0</span><span class="p">,</span> <span class="s">&quot;b&quot;</span><span class="p">:</span> <span class="mf">0</span><span class="p">,</span> <span class="s">&quot;a&quot;</span><span class="p">:</span> <span class="mf">0</span><span class="p">},</span> <span class="n">sort_keys</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
  59. <span class="go">{&quot;a&quot;: 0, &quot;b&quot;: 0, &quot;c&quot;: 0}</span>
  60. <span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">StringIO</span> <span class="k">import</span> <span class="n">StringIO</span>
  61. <span class="gp">&gt;&gt;&gt; </span><span class="n">io</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
  62. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">([</span><span class="s">&#39;streaming API&#39;</span><span class="p">],</span> <span class="n">io</span><span class="p">)</span>
  63. <span class="gp">&gt;&gt;&gt; </span><span class="n">io</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
  64. <span class="go">&#39;[&quot;streaming API&quot;]&#39;</span>
  65. </pre></div>
  66. <p>Compact encoding:</p>
  67. <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>
  68. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">([</span><span class="mf">1</span><span class="p">,</span><span class="mf">2</span><span class="p">,</span><span class="mf">3</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">separators</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">,</span><span class="s">&#39;:&#39;</span><span class="p">))</span>
  69. <span class="go">&#39;[1,2,3,{&quot;4&quot;:5,&quot;6&quot;:7}]&#39;</span>
  70. </pre></div>
  71. <p>Pretty printing:</p>
  72. <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>
  73. <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>
  74. <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>
  75. <span class="go">{</span>
  76. <span class="go"> &quot;4&quot;: 5,</span>
  77. <span class="go"> &quot;6&quot;: 7</span>
  78. <span class="go">}</span>
  79. </pre></div>
  80. <p>Decoding JSON:</p>
  81. <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>
  82. <span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="p">[</span><span class="s">u&#39;foo&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">u&#39;bar&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">u&#39;baz&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">2</span><span class="p">]}]</span>
  83. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">&#39;[&quot;foo&quot;, {&quot;bar&quot;:[&quot;baz&quot;, null, 1.0, 2]}]&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="n">obj</span>
  84. <span class="go">True</span>
  85. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">&#39;&quot;</span><span class="se">\\</span><span class="s">&quot;foo</span><span class="se">\\</span><span class="s">bar&quot;&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">u&#39;&quot;foo</span><span class="se">\x08</span><span class="s">ar&#39;</span>
  86. <span class="go">True</span>
  87. <span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">StringIO</span> <span class="k">import</span> <span class="n">StringIO</span>
  88. <span class="gp">&gt;&gt;&gt; </span><span class="n">io</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s">&#39;[&quot;streaming API&quot;]&#39;</span><span class="p">)</span>
  89. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">io</span><span class="p">)[</span><span class="mf">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;streaming API&#39;</span>
  90. <span class="go">True</span>
  91. </pre></div>
  92. <p>Specializing JSON object decoding:</p>
  93. <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>
  94. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">as_complex</span><span class="p">(</span><span class="n">dct</span><span class="p">):</span>
  95. <span class="gp">... </span> <span class="k">if</span> <span class="s">&#39;__complex__&#39;</span> <span class="ow">in</span> <span class="n">dct</span><span class="p">:</span>
  96. <span class="gp">... </span> <span class="k">return</span> <span class="nb">complex</span><span class="p">(</span><span class="n">dct</span><span class="p">[</span><span class="s">&#39;real&#39;</span><span class="p">],</span> <span class="n">dct</span><span class="p">[</span><span class="s">&#39;imag&#39;</span><span class="p">])</span>
  97. <span class="gp">... </span> <span class="k">return</span> <span class="n">dct</span>
  98. <span class="gp">...</span>
  99. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">&#39;{&quot;__complex__&quot;: true, &quot;real&quot;: 1, &quot;imag&quot;: 2}&#39;</span><span class="p">,</span>
  100. <span class="gp">... </span> <span class="n">object_hook</span><span class="o">=</span><span class="n">as_complex</span><span class="p">)</span>
  101. <span class="go">(1+2j)</span>
  102. <span class="gp">&gt;&gt;&gt; </span><span class="k">import</span> <span class="nn">decimal</span>
  103. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">&#39;1.1&#39;</span><span class="p">,</span> <span class="n">parse_float</span><span class="o">=</span><span class="n">decimal</span><span class="o">.</span><span class="n">Decimal</span><span class="p">)</span> <span class="o">==</span> <span class="n">decimal</span><span class="o">.</span><span class="n">Decimal</span><span class="p">(</span><span class="s">&#39;1.1&#39;</span><span class="p">)</span>
  104. <span class="go">True</span>
  105. </pre></div>
  106. <p>Specializing JSON object encoding:</p>
  107. <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>
  108. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">encode_complex</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
  109. <span class="gp">... </span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">complex</span><span class="p">):</span>
  110. <span class="gp">... </span> <span class="k">return</span> <span class="p">[</span><span class="n">obj</span><span class="o">.</span><span class="n">real</span><span class="p">,</span> <span class="n">obj</span><span class="o">.</span><span class="n">imag</span><span class="p">]</span>
  111. <span class="gp">... </span> <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">o</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot; is not JSON serializable&quot;</span><span class="p">)</span>
  112. <span class="gp">...</span>
  113. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="mf">2</span> <span class="o">+</span> <span class="mf">1</span><span class="n">j</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">encode_complex</span><span class="p">)</span>
  114. <span class="go">&#39;[2.0, 1.0]&#39;</span>
  115. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">JSONEncoder</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="n">encode_complex</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="mf">2</span> <span class="o">+</span> <span class="mf">1</span><span class="n">j</span><span class="p">)</span>
  116. <span class="go">&#39;[2.0, 1.0]&#39;</span>
  117. <span class="gp">&gt;&gt;&gt; </span><span class="s">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">JSONEncoder</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="n">encode_complex</span><span class="p">)</span><span class="o">.</span><span class="n">iterencode</span><span class="p">(</span><span class="mf">2</span> <span class="o">+</span> <span class="mf">1</span><span class="n">j</span><span class="p">))</span>
  118. <span class="go">&#39;[2.0, 1.0]&#39;</span>
  119. </pre></div>
  120. <p>Using <tt class="xref docutils literal"><span class="pre">simplejson.tool</span></tt> from the shell to validate and pretty-print:</p>
  121. <div class="highlight"><pre>$ echo &#39;{&quot;json&quot;:&quot;obj&quot;}&#39; | python -m simplejson.tool
  122. {
  123. &quot;json&quot;: &quot;obj&quot;
  124. }
  125. $ echo &#39;{ 1.2:3.4}&#39; | python -m simplejson.tool
  126. Expecting property name: line 1 column 2 (char 2)
  127. </pre></div>
  128. <div class="admonition note">
  129. <p class="first admonition-title">Note</p>
  130. <p class="last">The JSON produced by this module&#8217;s default settings is a subset of
  131. YAML, so it may be used as a serializer for that as well.</p>
  132. </div>
  133. <div class="section" id="basic-usage">
  134. <h2 id="basic-usage">Basic Usage<a class="headerlink" href="#basic-usage" title="Permalink to this headline">¶</a></h2>
  135. <dl class="function">
  136. <dt id="simplejson.dump">
  137. <!--[simplejson.dump]--><tt class="descclassname">simplejson.</tt><tt class="descname">dump</tt><big>(</big><em>obj</em>, <em>fp</em><span class="optional">[</span>, <em>skipkeys</em><span class="optional">[</span>, <em>ensure_ascii</em><span class="optional">[</span>, <em>check_circular</em><span class="optional">[</span>, <em>allow_nan</em><span class="optional">[</span>, <em>cls</em><span class="optional">[</span>, <em>indent</em><span class="optional">[</span>, <em>separators</em><span class="optional">[</span>, <em>encoding</em><span class="optional">[</span>, <em>default</em><span class="optional">[</span>, <em>**kw</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.dump" title="Permalink to this definition">¶</a></dt>
  138. <dd><p>Serialize <em>obj</em> as a JSON formatted stream to <em>fp</em> (a <tt class="docutils literal"><span class="pre">.write()</span></tt>-supporting
  139. file-like object).</p>
  140. <p>If <em>skipkeys</em> is true (default: <tt class="xref docutils literal"><span class="pre">False</span></tt>), then dict keys that are not
  141. of a basic type (<tt class="xref docutils literal"><span class="pre">str</span></tt>, <tt class="xref docutils literal"><span class="pre">unicode</span></tt>, <tt class="xref docutils literal"><span class="pre">int</span></tt>, <tt class="xref docutils literal"><span class="pre">long</span></tt>,
  142. <tt class="xref docutils literal"><span class="pre">float</span></tt>, <tt class="xref docutils literal"><span class="pre">bool</span></tt>, <tt class="xref docutils literal"><span class="pre">None</span></tt>) will be skipped instead of raising a
  143. <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>.</p>
  144. <p>If <em>ensure_ascii</em> is false (default: <tt class="xref docutils literal"><span class="pre">True</span></tt>), then some chunks written
  145. to <em>fp</em> may be <tt class="xref docutils literal"><span class="pre">unicode</span></tt> instances, subject to normal Python
  146. <tt class="xref docutils literal"><span class="pre">str</span></tt> to <tt class="xref docutils literal"><span class="pre">unicode</span></tt> coercion rules. Unless <tt class="docutils literal"><span class="pre">fp.write()</span></tt>
  147. explicitly understands <tt class="xref docutils literal"><span class="pre">unicode</span></tt> (as in <tt class="xref docutils literal"><span class="pre">codecs.getwriter()</span></tt>) this
  148. is likely to cause an error. It&#8217;s best to leave the default settings, because
  149. they are safe and it is highly optimized.</p>
  150. <p>If <em>check_circular</em> is false (default: <tt class="xref docutils literal"><span class="pre">True</span></tt>), then the circular
  151. reference check for container types will be skipped and a circular reference
  152. will result in an <tt class="xref docutils literal"><span class="pre">OverflowError</span></tt> (or worse).</p>
  153. <p>If <em>allow_nan</em> is false (default: <tt class="xref docutils literal"><span class="pre">True</span></tt>), then it will be a
  154. <tt class="xref docutils literal"><span class="pre">ValueError</span></tt> to serialize out of range <tt class="xref docutils literal"><span class="pre">float</span></tt> values (<tt class="docutils literal"><span class="pre">nan</span></tt>,
  155. <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.
  156. If <em>allow_nan</em> is true, their JavaScript equivalents will be used
  157. (<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>
  158. <p>If <em>indent</em> is a non-negative integer, then JSON array elements and object
  159. members will be pretty-printed with that indent level. An indent level of 0
  160. will only insert newlines. <tt class="xref docutils literal"><span class="pre">None</span></tt> (the default) selects the most compact
  161. representation.</p>
  162. <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>
  163. 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
  164. representation, you should specify <tt class="docutils literal"><span class="pre">(',',</span> <span class="pre">':')</span></tt> to eliminate whitespace.</p>
  165. <p><em>encoding</em> is the character encoding for str instances, default is
  166. <tt class="docutils literal"><span class="pre">'utf-8'</span></tt>.</p>
  167. <p>If specified, <em>default</em> should be a function that gets called for objects
  168. that can&#8217;t otherwise be serialized. It should return a JSON encodable
  169. version of the object or raise a <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>. If not specified,
  170. <tt class="xref docutils literal"><span class="pre">TypeError</span></tt> is always raised in those cases.</p>
  171. <p>To use a custom <a title="simplejson.JSONEncoder" class="reference internal" href="#simplejson.JSONEncoder"><tt class="xref docutils literal"><span class="pre">JSONEncoder</span></tt></a> subclass (e.g. one that overrides the
  172. <tt class="xref docutils literal"><span class="pre">default()</span></tt> method to serialize additional types), specify it with the
  173. <em>cls</em> kwarg.</p>
  174. <blockquote>
  175. <div class="admonition note">
  176. <p class="first admonition-title">Note</p>
  177. <p class="last">JSON is not a framed protocol so unlike <tt class="xref docutils literal"><span class="pre">pickle</span></tt> or <tt class="xref docutils literal"><span class="pre">marshal</span></tt> it
  178. does not make sense to serialize more than one JSON document without some
  179. container protocol to delimit them.</p>
  180. </div>
  181. </blockquote>
  182. </dd></dl>
  183. <dl class="function">
  184. <dt id="simplejson.dumps">
  185. <!--[simplejson.dumps]--><tt class="descclassname">simplejson.</tt><tt class="descname">dumps</tt><big>(</big><em>obj</em><span class="optional">[</span>, <em>skipkeys</em><span class="optional">[</span>, <em>ensure_ascii</em><span class="optional">[</span>, <em>check_circular</em><span class="optional">[</span>, <em>allow_nan</em><span class="optional">[</span>, <em>cls</em><span class="optional">[</span>, <em>indent</em><span class="optional">[</span>, <em>separators</em><span class="optional">[</span>, <em>encoding</em><span class="optional">[</span>, <em>default</em><span class="optional">[</span>, <em>**kw</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.dumps" title="Permalink to this definition">¶</a></dt>
  186. <dd><p>Serialize <em>obj</em> to a JSON formatted <tt class="xref docutils literal"><span class="pre">str</span></tt>.</p>
  187. <p>If <em>ensure_ascii</em> is false, then the return value will be a
  188. <tt class="xref docutils literal"><span class="pre">unicode</span></tt> instance. The other arguments have the same meaning as in
  189. <a title="simplejson.dump" class="reference internal" href="#simplejson.dump"><tt class="xref docutils literal"><span class="pre">dump()</span></tt></a>. Note that the default <em>ensure_ascii</em> setting has much
  190. better performance.</p>
  191. </dd></dl>
  192. <dl class="function">
  193. <dt id="simplejson.load">
  194. <!--[simplejson.load]--><tt class="descclassname">simplejson.</tt><tt class="descname">load</tt><big>(</big><em>fp</em><span class="optional">[</span>, <em>encoding</em><span class="optional">[</span>, <em>cls</em><span class="optional">[</span>, <em>object_hook</em><span class="optional">[</span>, <em>parse_float</em><span class="optional">[</span>, <em>parse_int</em><span class="optional">[</span>, <em>parse_constant</em><span class="optional">[</span>, <em>**kw</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.load" title="Permalink to this definition">¶</a></dt>
  195. <dd><p>Deserialize <em>fp</em> (a <tt class="docutils literal"><span class="pre">.read()</span></tt>-supporting file-like object containing a JSON
  196. document) to a Python object.</p>
  197. <p>If the contents of <em>fp</em> are encoded with an ASCII based encoding other than
  198. UTF-8 (e.g. latin-1), then an appropriate <em>encoding</em> name must be specified.
  199. Encodings that are not ASCII based (such as UCS-2) are not allowed, and
  200. should be wrapped with <tt class="docutils literal"><span class="pre">codecs.getreader(fp)(encoding)</span></tt>, or simply decoded
  201. to a <tt class="xref docutils literal"><span class="pre">unicode</span></tt> object and passed to <a title="simplejson.loads" class="reference internal" href="#simplejson.loads"><tt class="xref docutils literal"><span class="pre">loads()</span></tt></a>. The default
  202. setting of <tt class="docutils literal"><span class="pre">'utf-8'</span></tt> is fastest and should be using whenever possible.</p>
  203. <p><em>object_hook</em> is an optional function that will be called with the result of
  204. any object literal decode (a <tt class="xref docutils literal"><span class="pre">dict</span></tt>). The return value of
  205. <em>object_hook</em> will be used instead of the <tt class="xref docutils literal"><span class="pre">dict</span></tt>. This feature can be used
  206. to implement custom decoders (e.g. JSON-RPC class hinting).</p>
  207. <p><em>parse_float</em>, if specified, will be called with the string of every JSON
  208. float to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">float(num_str)</span></tt>.
  209. This can be used to use another datatype or parser for JSON floats
  210. (e.g. <tt class="xref docutils literal"><span class="pre">decimal.Decimal</span></tt>).</p>
  211. <p><em>parse_int</em>, if specified, will be called with the string of every JSON int
  212. to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">int(num_str)</span></tt>. This can
  213. be used to use another datatype or parser for JSON integers
  214. (e.g. <tt class="xref docutils literal"><span class="pre">float</span></tt>).</p>
  215. <p><em>parse_constant</em>, if specified, will be called with one of the following
  216. strings: <tt class="docutils literal"><span class="pre">'-Infinity'</span></tt>, <tt class="docutils literal"><span class="pre">'Infinity'</span></tt>, <tt class="docutils literal"><span class="pre">'NaN'</span></tt>. This can be used to
  217. raise an exception if invalid JSON numbers are encountered.</p>
  218. <p>To use a custom <a title="simplejson.JSONDecoder" class="reference internal" href="#simplejson.JSONDecoder"><tt class="xref docutils literal"><span class="pre">JSONDecoder</span></tt></a> subclass, specify it with the <tt class="docutils literal"><span class="pre">cls</span></tt>
  219. kwarg. Additional keyword arguments will be passed to the constructor of the
  220. class.</p>
  221. <blockquote>
  222. <div class="admonition note">
  223. <p class="first admonition-title">Note</p>
  224. <p class="last"><a title="simplejson.load" class="reference internal" href="#simplejson.load"><tt class="xref docutils literal"><span class="pre">load()</span></tt></a> will read the rest of the file-like object as a string and
  225. then call <a title="simplejson.loads" class="reference internal" href="#simplejson.loads"><tt class="xref docutils literal"><span class="pre">loads()</span></tt></a>. It does not stop at the end of the first valid
  226. JSON document it finds and it will raise an error if there is anything
  227. other than whitespace after the document. Except for files containing
  228. only one JSON document, it is recommended to use <a title="simplejson.loads" class="reference internal" href="#simplejson.loads"><tt class="xref docutils literal"><span class="pre">loads()</span></tt></a>.</p>
  229. </div>
  230. </blockquote>
  231. </dd></dl>
  232. <dl class="function">
  233. <dt id="simplejson.loads">
  234. <!--[simplejson.loads]--><tt class="descclassname">simplejson.</tt><tt class="descname">loads</tt><big>(</big><em>s</em><span class="optional">[</span>, <em>encoding</em><span class="optional">[</span>, <em>cls</em><span class="optional">[</span>, <em>object_hook</em><span class="optional">[</span>, <em>parse_float</em><span class="optional">[</span>, <em>parse_int</em><span class="optional">[</span>, <em>parse_constant</em><span class="optional">[</span>, <em>**kw</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.loads" title="Permalink to this definition">¶</a></dt>
  235. <dd><p>Deserialize <em>s</em> (a <tt class="xref docutils literal"><span class="pre">str</span></tt> or <tt class="xref docutils literal"><span class="pre">unicode</span></tt> instance containing a JSON
  236. document) to a Python object.</p>
  237. <p>If <em>s</em> is a <tt class="xref docutils literal"><span class="pre">str</span></tt> instance and is encoded with an ASCII based encoding
  238. other than UTF-8 (e.g. latin-1), then an appropriate <em>encoding</em> name must be
  239. specified. Encodings that are not ASCII based (such as UCS-2) are not
  240. allowed and should be decoded to <tt class="xref docutils literal"><span class="pre">unicode</span></tt> first.</p>
  241. <p>The other arguments have the same meaning as in <a title="simplejson.load" class="reference internal" href="#simplejson.load"><tt class="xref docutils literal"><span class="pre">load()</span></tt></a>.</p>
  242. </dd></dl>
  243. </div>
  244. <div class="section" id="encoders-and-decoders">
  245. <h2 id="encoders-and-decoders">Encoders and decoders<a class="headerlink" href="#encoders-and-decoders" title="Permalink to this headline">¶</a></h2>
  246. <dl class="class">
  247. <dt id="simplejson.JSONDecoder">
  248. <!--[simplejson.JSONDecoder]-->class <tt class="descclassname">simplejson.</tt><tt class="descname">JSONDecoder</tt><big>(</big><span class="optional">[</span><em>encoding</em><span class="optional">[</span>, <em>object_hook</em><span class="optional">[</span>, <em>parse_float</em><span class="optional">[</span>, <em>parse_int</em><span class="optional">[</span>, <em>parse_constant</em><span class="optional">[</span>, <em>strict</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.JSONDecoder" title="Permalink to this definition">¶</a></dt>
  249. <dd><p>Simple JSON decoder.</p>
  250. <p>Performs the following translations in decoding by default:</p>
  251. <table border="1" class="docutils">
  252. <colgroup>
  253. <col width="44%" />
  254. <col width="56%" />
  255. </colgroup>
  256. <thead valign="bottom">
  257. <tr><th class="head">JSON</th>
  258. <th class="head">Python</th>
  259. </tr>
  260. </thead>
  261. <tbody valign="top">
  262. <tr><td>object</td>
  263. <td>dict</td>
  264. </tr>
  265. <tr><td>array</td>
  266. <td>list</td>
  267. </tr>
  268. <tr><td>string</td>
  269. <td>unicode</td>
  270. </tr>
  271. <tr><td>number (int)</td>
  272. <td>int, long</td>
  273. </tr>
  274. <tr><td>number (real)</td>
  275. <td>float</td>
  276. </tr>
  277. <tr><td>true</td>
  278. <td>True</td>
  279. </tr>
  280. <tr><td>false</td>
  281. <td>False</td>
  282. </tr>
  283. <tr><td>null</td>
  284. <td>None</td>
  285. </tr>
  286. </tbody>
  287. </table>
  288. <p>It also understands <tt class="docutils literal"><span class="pre">NaN</span></tt>, <tt class="docutils literal"><span class="pre">Infinity</span></tt>, and <tt class="docutils literal"><span class="pre">-Infinity</span></tt> as their
  289. corresponding <tt class="docutils literal"><span class="pre">float</span></tt> values, which is outside the JSON spec.</p>
  290. <p><em>encoding</em> determines the encoding used to interpret any <tt class="xref docutils literal"><span class="pre">str</span></tt> objects
  291. decoded by this instance (<tt class="docutils literal"><span class="pre">'utf-8'</span></tt> by default). It has no effect when decoding
  292. <tt class="xref docutils literal"><span class="pre">unicode</span></tt> objects.</p>
  293. <p>Note that currently only encodings that are a superset of ASCII work, strings
  294. of other encodings should be passed in as <tt class="xref docutils literal"><span class="pre">unicode</span></tt>.</p>
  295. <p><em>object_hook</em>, if specified, will be called with the result of every JSON
  296. object decoded and its return value will be used in place of the given
  297. <tt class="xref docutils literal"><span class="pre">dict</span></tt>. This can be used to provide custom deserializations (e.g. to
  298. support JSON-RPC class hinting).</p>
  299. <p><em>parse_float</em>, if specified, will be called with the string of every JSON
  300. float to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">float(num_str)</span></tt>.
  301. This can be used to use another datatype or parser for JSON floats
  302. (e.g. <tt class="xref docutils literal"><span class="pre">decimal.Decimal</span></tt>).</p>
  303. <p><em>parse_int</em>, if specified, will be called with the string of every JSON int
  304. to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">int(num_str)</span></tt>. This can
  305. be used to use another datatype or parser for JSON integers
  306. (e.g. <tt class="xref docutils literal"><span class="pre">float</span></tt>).</p>
  307. <p><em>parse_constant</em>, if specified, will be called with one of the following
  308. strings: <tt class="docutils literal"><span class="pre">'-Infinity'</span></tt>, <tt class="docutils literal"><span class="pre">'Infinity'</span></tt>, <tt class="docutils literal"><span class="pre">'NaN'</span></tt>. This can be used to
  309. raise an exception if invalid JSON numbers are encountered.</p>
  310. <p><em>strict</em> controls the parser&#8217;s behavior when it encounters an invalid
  311. control character in a string. The default setting of <tt class="xref docutils literal"><span class="pre">True</span></tt> means that
  312. unescaped control characters are parse errors, if <tt class="xref docutils literal"><span class="pre">False</span></tt> then control
  313. characters will be allowed in strings.</p>
  314. <dl class="method">
  315. <dt id="simplejson.JSONDecoder.decode">
  316. <!--[simplejson.JSONDecoder.decode]--><tt class="descname">decode</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#simplejson.JSONDecoder.decode" title="Permalink to this definition">¶</a></dt>
  317. <dd>Return the Python representation of <em>s</em> (a <tt class="xref docutils literal"><span class="pre">str</span></tt> or
  318. <tt class="xref docutils literal"><span class="pre">unicode</span></tt> instance containing a JSON document)</dd></dl>
  319. <dl class="method">
  320. <dt id="simplejson.JSONDecoder.raw_decode">
  321. <!--[simplejson.JSONDecoder.raw_decode]--><tt class="descname">raw_decode</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#simplejson.JSONDecoder.raw_decode" title="Permalink to this definition">¶</a></dt>
  322. <dd><p>Decode a JSON document from <em>s</em> (a <tt class="xref docutils literal"><span class="pre">str</span></tt> or <tt class="xref docutils literal"><span class="pre">unicode</span></tt>
  323. beginning with a JSON document) and return a 2-tuple of the Python
  324. representation and the index in <em>s</em> where the document ended.</p>
  325. <p>This can be used to decode a JSON document from a string that may have
  326. extraneous data at the end.</p>
  327. </dd></dl>
  328. </dd></dl>
  329. <dl class="class">
  330. <dt id="simplejson.JSONEncoder">
  331. <!--[simplejson.JSONEncoder]-->class <tt class="descclassname">simplejson.</tt><tt class="descname">JSONEncoder</tt><big>(</big><span class="optional">[</span><em>skipkeys</em><span class="optional">[</span>, <em>ensure_ascii</em><span class="optional">[</span>, <em>check_circular</em><span class="optional">[</span>, <em>allow_nan</em><span class="optional">[</span>, <em>sort_keys</em><span class="optional">[</span>, <em>indent</em><span class="optional">[</span>, <em>separators</em><span class="optional">[</span>, <em>encoding</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.JSONEncoder" title="Permalink to this definition">¶</a></dt>
  332. <dd><p>Extensible JSON encoder for Python data structures.</p>
  333. <p>Supports the following objects and types by default:</p>
  334. <table border="1" class="docutils">
  335. <colgroup>
  336. <col width="56%" />
  337. <col width="44%" />
  338. </colgroup>
  339. <thead valign="bottom">
  340. <tr><th class="head">Python</th>
  341. <th class="head">JSON</th>
  342. </tr>
  343. </thead>
  344. <tbody valign="top">
  345. <tr><td>dict</td>
  346. <td>object</td>
  347. </tr>
  348. <tr><td>list, tuple</td>
  349. <td>array</td>
  350. </tr>
  351. <tr><td>str, unicode</td>
  352. <td>string</td>
  353. </tr>
  354. <tr><td>int, long, float</td>
  355. <td>number</td>
  356. </tr>
  357. <tr><td>True</td>
  358. <td>true</td>
  359. </tr>
  360. <tr><td>False</td>
  361. <td>false</td>
  362. </tr>
  363. <tr><td>None</td>
  364. <td>null</td>
  365. </tr>
  366. </tbody>
  367. </table>
  368. <p>To extend this to recognize other objects, subclass and implement a
  369. <a title="simplejson.JSONEncoder.default" class="reference internal" href="#simplejson.JSONEncoder.default"><tt class="xref docutils literal"><span class="pre">default()</span></tt></a> method with another method that returns a serializable object
  370. for <tt class="docutils literal"><span class="pre">o</span></tt> if possible, otherwise it should call the superclass implementation
  371. (to raise <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>).</p>
  372. <p>If <em>skipkeys</em> is false (the default), then it is a <tt class="xref docutils literal"><span class="pre">TypeError</span></tt> to
  373. attempt encoding of keys that are not str, int, long, float or None. If
  374. <em>skipkeys</em> is true, such items are simply skipped.</p>
  375. <p>If <em>ensure_ascii</em> is true (the default), the output is guaranteed to be
  376. <tt class="xref docutils literal"><span class="pre">str</span></tt> objects with all incoming unicode characters escaped. If
  377. <em>ensure_ascii</em> is false, the output will be a unicode object.</p>
  378. <p>If <em>check_circular</em> is false (the default), then lists, dicts, and custom
  379. encoded objects will be checked for circular references during encoding to
  380. prevent an infinite recursion (which would cause an <tt class="xref docutils literal"><span class="pre">OverflowError</span></tt>).
  381. Otherwise, no such check takes place.</p>
  382. <p>If <em>allow_nan</em> is true (the default), then <tt class="docutils literal"><span class="pre">NaN</span></tt>, <tt class="docutils literal"><span class="pre">Infinity</span></tt>, and
  383. <tt class="docutils literal"><span class="pre">-Infinity</span></tt> will be encoded as such. This behavior is not JSON
  384. specification compliant, but is consistent with most JavaScript based
  385. encoders and decoders. Otherwise, it will be a <tt class="xref docutils literal"><span class="pre">ValueError</span></tt> to encode
  386. such floats.</p>
  387. <p>If <em>sort_keys</em> is true (the default), then the output of dictionaries
  388. will be sorted by key; this is useful for regression tests to ensure that
  389. JSON serializations can be compared on a day-to-day basis.</p>
  390. <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
  391. array elements and object members will be pretty-printed with that indent
  392. level. An indent level of 0 will only insert newlines. <tt class="xref docutils literal"><span class="pre">None</span></tt> is the most
  393. compact representation.</p>
  394. <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>
  395. 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
  396. representation, you should specify <tt class="docutils literal"><span class="pre">(',',</span> <span class="pre">':')</span></tt> to eliminate whitespace.</p>
  397. <p>If specified, <em>default</em> should be a function that gets called for objects
  398. that can&#8217;t otherwise be serialized. It should return a JSON encodable
  399. version of the object or raise a <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>.</p>
  400. <p>If <em>encoding</em> is not <tt class="xref docutils literal"><span class="pre">None</span></tt>, then all input strings will be transformed
  401. into unicode using that encoding prior to JSON-encoding. The default is
  402. <tt class="docutils literal"><span class="pre">'utf-8'</span></tt>.</p>
  403. <dl class="method">
  404. <dt id="simplejson.JSONEncoder.default">
  405. <!--[simplejson.JSONEncoder.default]--><tt class="descname">default</tt><big>(</big><em>o</em><big>)</big><a class="headerlink" href="#simplejson.JSONEncoder.default" title="Permalink to this definition">¶</a></dt>
  406. <dd><p>Implement this method in a subclass such that it returns a serializable
  407. object for <em>o</em>, or calls the base implementation (to raise a
  408. <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>).</p>
  409. <p>For example, to support arbitrary iterators, you could implement default
  410. like this:</p>
  411. <div class="highlight"><pre><span class="k">def</span> <span class="nf">default</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">o</span><span class="p">):</span>
  412. <span class="k">try</span><span class="p">:</span>
  413. <span class="n">iterable</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
  414. <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
  415. <span class="k">pass</span>
  416. <span class="k">else</span><span class="p">:</span>
  417. <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">iterable</span><span class="p">)</span>
  418. <span class="k">return</span> <span class="n">JSONEncoder</span><span class="o">.</span><span class="n">default</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">o</span><span class="p">)</span>
  419. </pre></div>
  420. </dd></dl>
  421. <dl class="method">
  422. <dt id="simplejson.JSONEncoder.encode">
  423. <!--[simplejson.JSONEncoder.encode]--><tt class="descname">encode</tt><big>(</big><em>o</em><big>)</big><a class="headerlink" href="#simplejson.JSONEncoder.encode" title="Permalink to this definition">¶</a></dt>
  424. <dd><p>Return a JSON string representation of a Python data structure, <em>o</em>. For
  425. example:</p>
  426. <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>
  427. <span class="gp">&gt;&gt;&gt; </span><span class="n">json</span><span class="o">.</span><span class="n">JSONEncoder</span><span class="p">()</span><span class="o">.</span><span class="n">encode</span><span class="p">({</span><span class="s">&quot;foo&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s">&quot;bar&quot;</span><span class="p">,</span> <span class="s">&quot;baz&quot;</span><span class="p">]})</span>
  428. <span class="go">&#39;{&quot;foo&quot;: [&quot;bar&quot;, &quot;baz&quot;]}&#39;</span>
  429. </pre></div>
  430. </dd></dl>
  431. <dl class="method">
  432. <dt id="simplejson.JSONEncoder.iterencode">
  433. <!--[simplejson.JSONEncoder.iterencode]--><tt class="descname">iterencode</tt><big>(</big><em>o</em><big>)</big><a class="headerlink" href="#simplejson.JSONEncoder.iterencode" title="Permalink to this definition">¶</a></dt>
  434. <dd><p>Encode the given object, <em>o</em>, and yield each string representation as
  435. available. For example:</p>
  436. <div class="highlight"><pre><span class="k">for</span> <span class="n">chunk</span> <span class="ow">in</span> <span class="n">JSONEncoder</span><span class="p">()</span><span class="o">.</span><span class="n">iterencode</span><span class="p">(</span><span class="n">bigobject</span><span class="p">):</span>
  437. <span class="n">mysocket</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
  438. </pre></div>
  439. <p>Note that <a title="simplejson.JSONEncoder.encode" class="reference internal" href="#simplejson.JSONEncoder.encode"><tt class="xref docutils literal"><span class="pre">encode()</span></tt></a> has much better performance than
  440. <a title="simplejson.JSONEncoder.iterencode" class="reference internal" href="#simplejson.JSONEncoder.iterencode"><tt class="xref docutils literal"><span class="pre">iterencode()</span></tt></a>.</p>
  441. </dd></dl>
  442. </dd></dl>
  443. </div>
  444. </div>
  445. </div>
  446. </div>
  447. </div>
  448. <div class="sphinxsidebar">
  449. <div class="sphinxsidebarwrapper">
  450. <h3>Table Of Contents</h3>
  451. <ul>
  452. <li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">simplejson</span></tt> &#8212; JSON encoder and decoder</a><ul>
  453. <li><a class="reference external" href="#basic-usage">Basic Usage</a></li>
  454. <li><a class="reference external" href="#encoders-and-decoders">Encoders and decoders</a></li>
  455. </ul>
  456. </li>
  457. </ul>
  458. <h3>This Page</h3>
  459. <ul class="this-page-menu">
  460. <li><a href="_sources/index.txt">Show Source</a></li>
  461. </ul>
  462. <h3>Quick search</h3>
  463. <form class="search" action="search.html" method="get">
  464. <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
  465. <input type="hidden" name="check_keywords" value="yes" />
  466. <input type="hidden" name="area" value="default" />
  467. </form>
  468. </div>
  469. </div>
  470. <div class="clearer"></div>
  471. </div>
  472. <div class="related">
  473. <h3>Navigation</h3>
  474. <ul>
  475. <li class="right" style="margin-right: 10px">
  476. <a href="genindex.html" title="General Index"
  477. accesskey="I">index</a></li>
  478. <li><a href="">simplejson v2.0.0 documentation</a> &raquo;</li>
  479. </ul>
  480. </div>
  481. <div class="footer">
  482. &copy; Copyright 2008, Bob Ippolito.
  483. Last updated on Feb 18, 2009.
  484. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  485. </div>
  486. </body>
  487. </html>