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">
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
<title>simplejson — JSON encoder and decoder — simplejson v2.1.1 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 = {
12
COLLAPSE_MODINDEX: false,
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.1.1 documentation" href="" />
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.1.1 documentation</a> »</li>
34
<div class="document">
35
<div class="documentwrapper">
36
<div class="bodywrapper">
40
<div class="section" id="module-simplejson">
41
<h1 id="module-simplejson"><tt class="xref docutils literal"><span class="pre">simplejson</span></tt> — JSON encoder and decoder<a class="headerlink" href="#module-simplejson" title="Permalink to this headline">¶</a></h1>
42
<p>JSON (JavaScript Object Notation) <<a class="reference external" href="http://json.org">http://json.org</a>> is a subset of JavaScript
43
syntax (ECMA-262 3rd edition) used as a lightweight data interchange format.</p>
44
<p><tt class="xref docutils literal"><span class="pre">simplejson</span></tt> exposes an API familiar to users of the standard library
45
<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
46
version of the <tt class="xref docutils literal"><span class="pre">json</span></tt> library contained in Python 2.6, but maintains
47
compatibility with Python 2.5 and (currently) has
48
significant performance advantages, even without using the optional C
49
extension for speedups.</p>
50
<p>Encoding basic Python object hierarchies:</p>
51
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
52
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">([</span><span class="s">'foo'</span><span class="p">,</span> <span class="p">{</span><span class="s">'bar'</span><span class="p">:</span> <span class="p">(</span><span class="s">'baz'</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>
53
<span class="go">'["foo", {"bar": ["baz", null, 1.0, 2]}]'</span>
54
<span class="gp">>>> </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">"</span><span class="se">\"</span><span class="s">foo</span><span class="se">\b</span><span class="s">ar"</span><span class="p">)</span>
55
<span class="go">"\"foo\bar"</span>
56
<span class="gp">>>> </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'</span><span class="se">\u1234</span><span class="s">'</span><span class="p">)</span>
57
<span class="go">"\u1234"</span>
58
<span class="gp">>>> </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">'</span><span class="se">\\</span><span class="s">'</span><span class="p">)</span>
59
<span class="go">"\\"</span>
60
<span class="gp">>>> </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">"c"</span><span class="p">:</span> <span class="mf">0</span><span class="p">,</span> <span class="s">"b"</span><span class="p">:</span> <span class="mf">0</span><span class="p">,</span> <span class="s">"a"</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>
61
<span class="go">{"a": 0, "b": 0, "c": 0}</span>
62
<span class="gp">>>> </span><span class="k">from</span> <span class="nn">StringIO</span> <span class="k">import</span> <span class="n">StringIO</span>
63
<span class="gp">>>> </span><span class="n">io</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
64
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">([</span><span class="s">'streaming API'</span><span class="p">],</span> <span class="n">io</span><span class="p">)</span>
65
<span class="gp">>>> </span><span class="n">io</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
66
<span class="go">'["streaming API"]'</span>
68
<p>Compact encoding:</p>
69
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
70
<span class="gp">>>> </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">'4'</span><span class="p">:</span> <span class="mf">5</span><span class="p">,</span> <span class="s">'6'</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">','</span><span class="p">,</span><span class="s">':'</span><span class="p">))</span>
71
<span class="go">'[1,2,3,{"4":5,"6":7}]'</span>
73
<p>Pretty printing:</p>
74
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
75
<span class="gp">>>> </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">'4'</span><span class="p">:</span> <span class="mf">5</span><span class="p">,</span> <span class="s">'6'</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="o">*</span> <span class="s">' '</span><span class="p">)</span>
76
<span class="gp">>>> </span><span class="k">print</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</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>
77
<span class="go">{</span>
78
<span class="go"> "4": 5,</span>
79
<span class="go"> "6": 7</span>
80
<span class="go">}</span>
83
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
84
<span class="gp">>>> </span><span class="n">obj</span> <span class="o">=</span> <span class="p">[</span><span class="s">u'foo'</span><span class="p">,</span> <span class="p">{</span><span class="s">u'bar'</span><span class="p">:</span> <span class="p">[</span><span class="s">u'baz'</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>
85
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">'["foo", {"bar":["baz", null, 1.0, 2]}]'</span><span class="p">)</span> <span class="o">==</span> <span class="n">obj</span>
86
<span class="go">True</span>
87
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">'"</span><span class="se">\\</span><span class="s">"foo</span><span class="se">\\</span><span class="s">bar"'</span><span class="p">)</span> <span class="o">==</span> <span class="s">u'"foo</span><span class="se">\x08</span><span class="s">ar'</span>
88
<span class="go">True</span>
89
<span class="gp">>>> </span><span class="k">from</span> <span class="nn">StringIO</span> <span class="k">import</span> <span class="n">StringIO</span>
90
<span class="gp">>>> </span><span class="n">io</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s">'["streaming API"]'</span><span class="p">)</span>
91
<span class="gp">>>> </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">'streaming API'</span>
92
<span class="go">True</span>
94
<p>Using Decimal instead of float:</p>
95
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
96
<span class="gp">>>> </span><span class="k">from</span> <span class="nn">decimal</span> <span class="k">import</span> <span class="n">Decimal</span>
97
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">'1.1'</span><span class="p">,</span> <span class="n">use_decimal</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="o">==</span> <span class="n">Decimal</span><span class="p">(</span><span class="s">'1.1'</span><span class="p">)</span>
98
<span class="go">True</span>
99
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">Decimal</span><span class="p">(</span><span class="s">'1.1'</span><span class="p">),</span> <span class="n">use_decimal</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="o">==</span> <span class="s">'1.1'</span>
100
<span class="go">True</span>
102
<p>Specializing JSON object decoding:</p>
103
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
104
<span class="gp">>>> </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>
105
<span class="gp">... </span> <span class="k">if</span> <span class="s">'__complex__'</span> <span class="ow">in</span> <span class="n">dct</span><span class="p">:</span>
106
<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">'real'</span><span class="p">],</span> <span class="n">dct</span><span class="p">[</span><span class="s">'imag'</span><span class="p">])</span>
107
<span class="gp">... </span> <span class="k">return</span> <span class="n">dct</span>
108
<span class="gp">...</span>
109
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">'{"__complex__": true, "real": 1, "imag": 2}'</span><span class="p">,</span>
110
<span class="gp">... </span> <span class="n">object_hook</span><span class="o">=</span><span class="n">as_complex</span><span class="p">)</span>
111
<span class="go">(1+2j)</span>
112
<span class="gp">>>> </span><span class="k">import</span> <span class="nn">decimal</span>
113
<span class="gp">>>> </span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s">'1.1'</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">'1.1'</span><span class="p">)</span>
114
<span class="go">True</span>
116
<p>Specializing JSON object encoding:</p>
117
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
118
<span class="gp">>>> </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>
119
<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>
120
<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>
121
<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">" is not JSON serializable"</span><span class="p">)</span>
122
<span class="gp">...</span>
123
<span class="gp">>>> </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>
124
<span class="go">'[2.0, 1.0]'</span>
125
<span class="gp">>>> </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>
126
<span class="go">'[2.0, 1.0]'</span>
127
<span class="gp">>>> </span><span class="s">''</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>
128
<span class="go">'[2.0, 1.0]'</span>
130
<p>Using <tt class="xref docutils literal"><span class="pre">simplejson.tool</span></tt> from the shell to validate and pretty-print:</p>
131
<div class="highlight"><pre>$ echo '{"json":"obj"}' | python -m simplejson.tool
133
"json": "obj"
135
$ echo '{ 1.2:3.4}' | python -m simplejson.tool
136
Expecting property name: line 1 column 2 (char 2)
138
<div class="admonition note">
139
<p class="first admonition-title">Note</p>
140
<p class="last">The JSON produced by this module’s default settings is a subset of
141
YAML, so it may be used as a serializer for that as well.</p>
143
<div class="section" id="basic-usage">
144
<h2 id="basic-usage">Basic Usage<a class="headerlink" href="#basic-usage" title="Permalink to this headline">¶</a></h2>
145
<dl class="function">
146
<dt id="simplejson.dump">
147
<!--[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>use_decimal</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><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.dump" title="Permalink to this definition">¶</a></dt>
148
<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
149
file-like object).</p>
150
<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
151
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>,
152
<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
153
<tt class="xref docutils literal"><span class="pre">TypeError</span></tt>.</p>
154
<p>If <em>ensure_ascii</em> is false (default: <tt class="xref docutils literal"><span class="pre">True</span></tt>), then some chunks written
155
to <em>fp</em> may be <tt class="xref docutils literal"><span class="pre">unicode</span></tt> instances, subject to normal Python
156
<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>
157
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
158
is likely to cause an error. It’s best to leave the default settings, because
159
they are safe and it is highly optimized.</p>
160
<p>If <em>check_circular</em> is false (default: <tt class="xref docutils literal"><span class="pre">True</span></tt>), then the circular
161
reference check for container types will be skipped and a circular reference
162
will result in an <tt class="xref docutils literal"><span class="pre">OverflowError</span></tt> (or worse).</p>
163
<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
164
<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>,
165
<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.
166
If <em>allow_nan</em> is true, their JavaScript equivalents will be used
167
(<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>
168
<p>If <em>indent</em> is a string, then JSON array elements and object members
169
will be pretty-printed with a newline followed by that string repeated
170
for each level of nesting. <tt class="xref docutils literal"><span class="pre">None</span></tt> (the default) selects the most compact
171
representation without any newlines. For backwards compatibility with
172
versions of simplejson earlier than 2.1.0, an integer is also accepted
173
and is converted to a string with that many spaces.</p>
175
<span class="versionmodified">Changed in version 2.1.0: </span>Changed <em>indent</em> from an integer number of spaces to a string.</p>
176
<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>
177
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
178
representation, you should specify <tt class="docutils literal"><span class="pre">(',',</span> <span class="pre">':')</span></tt> to eliminate whitespace.</p>
179
<p><em>encoding</em> is the character encoding for str instances, default is
180
<tt class="docutils literal"><span class="pre">'utf-8'</span></tt>.</p>
181
<p><em>default(obj)</em> is a function that should return a serializable version of
182
<em>obj</em> or raise <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>. The default simply raises <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>.</p>
183
<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
184
<tt class="xref docutils literal"><span class="pre">default()</span></tt> method to serialize additional types), specify it with the
185
<em>cls</em> kwarg.</p>
186
<p>If <em>use_decimal</em> is true (default: <tt class="xref docutils literal"><span class="pre">False</span></tt>) then <tt class="xref docutils literal"><span class="pre">decimal.Decimal</span></tt>
187
will be natively serialized to JSON with full precision.</p>
189
<span class="versionmodified">Changed in version 2.1.0: </span><em>use_decimal</em> is new in 2.1.0.<div class="admonition note">
190
<p class="first admonition-title">Note</p>
191
<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
192
does not make sense to serialize more than one JSON document without some
193
container protocol to delimit them.</p>
198
<dl class="function">
199
<dt id="simplejson.dumps">
200
<!--[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>use_decimal</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><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.dumps" title="Permalink to this definition">¶</a></dt>
201
<dd><p>Serialize <em>obj</em> to a JSON formatted <tt class="xref docutils literal"><span class="pre">str</span></tt>.</p>
202
<p>If <em>ensure_ascii</em> is false, then the return value will be a
203
<tt class="xref docutils literal"><span class="pre">unicode</span></tt> instance. The other arguments have the same meaning as in
204
<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
205
better performance.</p>
208
<dl class="function">
209
<dt id="simplejson.load">
210
<!--[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>object_pairs_hook</em><span class="optional">[</span>, <em>use_decimal</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><big>)</big><a class="headerlink" href="#simplejson.load" title="Permalink to this definition">¶</a></dt>
211
<dd><p>Deserialize <em>fp</em> (a <tt class="docutils literal"><span class="pre">.read()</span></tt>-supporting file-like object containing a JSON
212
document) to a Python object.</p>
213
<p>If the contents of <em>fp</em> are encoded with an ASCII based encoding other than
214
UTF-8 (e.g. latin-1), then an appropriate <em>encoding</em> name must be specified.
215
Encodings that are not ASCII based (such as UCS-2) are not allowed, and
216
should be wrapped with <tt class="docutils literal"><span class="pre">codecs.getreader(fp)(encoding)</span></tt>, or simply decoded
217
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
218
setting of <tt class="docutils literal"><span class="pre">'utf-8'</span></tt> is fastest and should be using whenever possible.</p>
219
<p>If <em>fp.read()</em> returns <tt class="xref docutils literal"><span class="pre">str</span></tt> then decoded JSON strings that contain
220
only ASCII characters may be parsed as <tt class="xref docutils literal"><span class="pre">str</span></tt> for performance and
221
memory reasons. If your code expects only <tt class="xref docutils literal"><span class="pre">unicode</span></tt> the appropriate
222
solution is to wrap fp with a reader as demonstrated above.</p>
223
<p><em>object_hook</em> is an optional function that will be called with the result of
224
any object literal decode (a <tt class="xref docutils literal"><span class="pre">dict</span></tt>). The return value of
225
<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
226
to implement custom decoders (e.g. JSON-RPC class hinting).</p>
227
<p><em>object_pairs_hook</em> is an optional function that will be called with the
228
result of any object literal decode with an ordered list of pairs. The
229
return value of <em>object_pairs_hook</em> will be used instead of the
230
<tt class="xref docutils literal"><span class="pre">dict</span></tt>. This feature can be used to implement custom decoders that
231
rely on the order that the key and value pairs are decoded (for example,
232
<tt class="xref docutils literal"><span class="pre">collections.OrderedDict</span></tt> will remember the order of insertion). If
233
<em>object_hook</em> is also defined, the <em>object_pairs_hook</em> takes priority.</p>
235
<span class="versionmodified">Changed in version 2.1.0: </span>Added support for <em>object_pairs_hook</em>.</p>
236
<p><em>parse_float</em>, if specified, will be called with the string of every JSON
237
float to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">float(num_str)</span></tt>.
238
This can be used to use another datatype or parser for JSON floats
239
(e.g. <tt class="xref docutils literal"><span class="pre">decimal.Decimal</span></tt>).</p>
240
<p><em>parse_int</em>, if specified, will be called with the string of every JSON int
241
to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">int(num_str)</span></tt>. This can
242
be used to use another datatype or parser for JSON integers
243
(e.g. <tt class="xref docutils literal"><span class="pre">float</span></tt>).</p>
244
<p><em>parse_constant</em>, if specified, will be called with one of the following
245
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
246
raise an exception if invalid JSON numbers are encountered.</p>
247
<p>If <em>use_decimal</em> is true (default: <tt class="xref docutils literal"><span class="pre">False</span></tt>) then <em>parse_float</em> is set to
248
<tt class="xref docutils literal"><span class="pre">decimal.Decimal</span></tt>. This is a convenience for parity with the
249
<a title="simplejson.dump" class="reference internal" href="#simplejson.dump"><tt class="xref docutils literal"><span class="pre">dump()</span></tt></a> parameter.</p>
251
<span class="versionmodified">Changed in version 2.1.0: </span><em>use_decimal</em> is new in 2.1.0.</p>
252
<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>
253
kwarg. Additional keyword arguments will be passed to the constructor of the
256
<div class="admonition note">
257
<p class="first admonition-title">Note</p>
258
<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
259
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
260
JSON document it finds and it will raise an error if there is anything
261
other than whitespace after the document. Except for files containing
262
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>
267
<dl class="function">
268
<dt id="simplejson.loads">
269
<!--[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>object_pairs_hook</em><span class="optional">[</span>, <em>use_decimal</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><big>)</big><a class="headerlink" href="#simplejson.loads" title="Permalink to this definition">¶</a></dt>
270
<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
271
document) to a Python object.</p>
272
<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
273
other than UTF-8 (e.g. latin-1), then an appropriate <em>encoding</em> name must be
274
specified. Encodings that are not ASCII based (such as UCS-2) are not
275
allowed and should be decoded to <tt class="xref docutils literal"><span class="pre">unicode</span></tt> first.</p>
276
<p>If <em>s</em> is a <tt class="xref docutils literal"><span class="pre">str</span></tt> then decoded JSON strings that contain
277
only ASCII characters may be parsed as <tt class="xref docutils literal"><span class="pre">str</span></tt> for performance and
278
memory reasons. If your code expects only <tt class="xref docutils literal"><span class="pre">unicode</span></tt> the appropriate
279
solution is decode <em>s</em> to <tt class="xref docutils literal"><span class="pre">unicode</span></tt> prior to calling loads.</p>
280
<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>
284
<div class="section" id="encoders-and-decoders">
285
<h2 id="encoders-and-decoders">Encoders and decoders<a class="headerlink" href="#encoders-and-decoders" title="Permalink to this headline">¶</a></h2>
287
<dt id="simplejson.JSONDecoder">
288
<!--[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>object_pairs_hook</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><span class="optional">]</span><big>)</big><a class="headerlink" href="#simplejson.JSONDecoder" title="Permalink to this definition">¶</a></dt>
289
<dd><p>Simple JSON decoder.</p>
290
<p>Performs the following translations in decoding by default:</p>
291
<table border="1" class="docutils">
296
<thead valign="bottom">
297
<tr><th class="head">JSON</th>
298
<th class="head">Python</th>
311
<tr><td>number (int)</td>
314
<tr><td>number (real)</td>
328
<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
329
corresponding <tt class="docutils literal"><span class="pre">float</span></tt> values, which is outside the JSON spec.</p>
330
<p><em>encoding</em> determines the encoding used to interpret any <tt class="xref docutils literal"><span class="pre">str</span></tt> objects
331
decoded by this instance (<tt class="docutils literal"><span class="pre">'utf-8'</span></tt> by default). It has no effect when decoding
332
<tt class="xref docutils literal"><span class="pre">unicode</span></tt> objects.</p>
333
<p>Note that currently only encodings that are a superset of ASCII work, strings
334
of other encodings should be passed in as <tt class="xref docutils literal"><span class="pre">unicode</span></tt>.</p>
335
<p><em>object_hook</em> is an optional function that will be called with the result of
336
every JSON object decoded and its return value will be used in place of the
337
given <tt class="xref docutils literal"><span class="pre">dict</span></tt>. This can be used to provide custom deserializations
338
(e.g. to support JSON-RPC class hinting).</p>
339
<p><em>object_pairs_hook</em> is an optional function that will be called with the
340
result of any object literal decode with an ordered list of pairs. The
341
return value of <em>object_pairs_hook</em> will be used instead of the
342
<tt class="xref docutils literal"><span class="pre">dict</span></tt>. This feature can be used to implement custom decoders that
343
rely on the order that the key and value pairs are decoded (for example,
344
<tt class="xref docutils literal"><span class="pre">collections.OrderedDict</span></tt> will remember the order of insertion). If
345
<em>object_hook</em> is also defined, the <em>object_pairs_hook</em> takes priority.</p>
347
<span class="versionmodified">Changed in version 2.1.0: </span>Added support for <em>object_pairs_hook</em>.</p>
348
<p><em>parse_float</em>, if specified, will be called with the string of every JSON
349
float to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">float(num_str)</span></tt>.
350
This can be used to use another datatype or parser for JSON floats
351
(e.g. <tt class="xref docutils literal"><span class="pre">decimal.Decimal</span></tt>).</p>
352
<p><em>parse_int</em>, if specified, will be called with the string of every JSON int
353
to be decoded. By default, this is equivalent to <tt class="docutils literal"><span class="pre">int(num_str)</span></tt>. This can
354
be used to use another datatype or parser for JSON integers
355
(e.g. <tt class="xref docutils literal"><span class="pre">float</span></tt>).</p>
356
<p><em>parse_constant</em>, if specified, will be called with one of the following
357
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
358
raise an exception if invalid JSON numbers are encountered.</p>
359
<p><em>strict</em> controls the parser’s behavior when it encounters an invalid
360
control character in a string. The default setting of <tt class="xref docutils literal"><span class="pre">True</span></tt> means that
361
unescaped control characters are parse errors, if <tt class="xref docutils literal"><span class="pre">False</span></tt> then control
362
characters will be allowed in strings.</p>
364
<dt id="simplejson.JSONDecoder.decode">
365
<!--[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>
366
<dd><p>Return the Python representation of <em>s</em> (a <tt class="xref docutils literal"><span class="pre">str</span></tt> or
367
<tt class="xref docutils literal"><span class="pre">unicode</span></tt> instance containing a JSON document)</p>
368
<p>If <em>s</em> is a <tt class="xref docutils literal"><span class="pre">str</span></tt> then decoded JSON strings that contain
369
only ASCII characters may be parsed as <tt class="xref docutils literal"><span class="pre">str</span></tt> for performance and
370
memory reasons. If your code expects only <tt class="xref docutils literal"><span class="pre">unicode</span></tt> the
371
appropriate solution is decode <em>s</em> to <tt class="xref docutils literal"><span class="pre">unicode</span></tt> prior to calling
376
<dt id="simplejson.JSONDecoder.raw_decode">
377
<!--[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>
378
<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>
379
beginning with a JSON document) and return a 2-tuple of the Python
380
representation and the index in <em>s</em> where the document ended.</p>
381
<p>This can be used to decode a JSON document from a string that may have
382
extraneous data at the end.</p>
388
<dt id="simplejson.JSONEncoder">
389
<!--[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>
390
<dd><p>Extensible JSON encoder for Python data structures.</p>
391
<p>Supports the following objects and types by default:</p>
392
<table border="1" class="docutils">
397
<thead valign="bottom">
398
<tr><th class="head">Python</th>
399
<th class="head">JSON</th>
406
<tr><td>list, tuple</td>
409
<tr><td>str, unicode</td>
412
<tr><td>int, long, float</td>
426
<p>To extend this to recognize other objects, subclass and implement a
427
<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
428
for <tt class="docutils literal"><span class="pre">o</span></tt> if possible, otherwise it should call the superclass implementation
429
(to raise <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>).</p>
430
<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
431
attempt encoding of keys that are not str, int, long, float or None. If
432
<em>skipkeys</em> is true, such items are simply skipped.</p>
433
<p>If <em>ensure_ascii</em> is true (the default), the output is guaranteed to be
434
<tt class="xref docutils literal"><span class="pre">str</span></tt> objects with all incoming unicode characters escaped. If
435
<em>ensure_ascii</em> is false, the output will be a unicode object.</p>
436
<p>If <em>check_circular</em> is false (the default), then lists, dicts, and custom
437
encoded objects will be checked for circular references during encoding to
438
prevent an infinite recursion (which would cause an <tt class="xref docutils literal"><span class="pre">OverflowError</span></tt>).
439
Otherwise, no such check takes place.</p>
440
<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
441
<tt class="docutils literal"><span class="pre">-Infinity</span></tt> will be encoded as such. This behavior is not JSON
442
specification compliant, but is consistent with most JavaScript based
443
encoders and decoders. Otherwise, it will be a <tt class="xref docutils literal"><span class="pre">ValueError</span></tt> to encode
445
<p>If <em>sort_keys</em> is true (not the default), then the output of dictionaries
446
will be sorted by key; this is useful for regression tests to ensure that
447
JSON serializations can be compared on a day-to-day basis.</p>
448
<p>If <em>indent</em> is a string, then JSON array elements and object members
449
will be pretty-printed with a newline followed by that string repeated
450
for each level of nesting. <tt class="xref docutils literal"><span class="pre">None</span></tt> (the default) selects the most compact
451
representation without any newlines. For backwards compatibility with
452
versions of simplejson earlier than 2.1.0, an integer is also accepted
453
and is converted to a string with that many spaces.</p>
455
<span class="versionmodified">Changed in version 2.1.0: </span>Changed <em>indent</em> from an integer number of spaces to a string.</p>
456
<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>
457
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
458
representation, you should specify <tt class="docutils literal"><span class="pre">(',',</span> <span class="pre">':')</span></tt> to eliminate whitespace.</p>
459
<p>If specified, <em>default</em> should be a function that gets called for objects
460
that can’t otherwise be serialized. It should return a JSON encodable
461
version of the object or raise a <tt class="xref docutils literal"><span class="pre">TypeError</span></tt>.</p>
462
<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
463
into unicode using that encoding prior to JSON-encoding. The default is
464
<tt class="docutils literal"><span class="pre">'utf-8'</span></tt>.</p>
466
<dt id="simplejson.JSONEncoder.default">
467
<!--[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>
468
<dd><p>Implement this method in a subclass such that it returns a serializable
469
object for <em>o</em>, or calls the base implementation (to raise a
470
<tt class="xref docutils literal"><span class="pre">TypeError</span></tt>).</p>
471
<p>For example, to support arbitrary iterators, you could implement default
473
<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>
474
<span class="k">try</span><span class="p">:</span>
475
<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>
476
<span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
477
<span class="k">pass</span>
478
<span class="k">else</span><span class="p">:</span>
479
<span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">iterable</span><span class="p">)</span>
480
<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>
485
<dt id="simplejson.JSONEncoder.encode">
486
<!--[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>
487
<dd><p>Return a JSON string representation of a Python data structure, <em>o</em>. For
489
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">import</span> <span class="nn">simplejson</span> <span class="k">as</span> <span class="nn">json</span>
490
<span class="gp">>>> </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">"foo"</span><span class="p">:</span> <span class="p">[</span><span class="s">"bar"</span><span class="p">,</span> <span class="s">"baz"</span><span class="p">]})</span>
491
<span class="go">'{"foo": ["bar", "baz"]}'</span>
496
<dt id="simplejson.JSONEncoder.iterencode">
497
<!--[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>
498
<dd><p>Encode the given object, <em>o</em>, and yield each string representation as
499
available. For example:</p>
500
<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>
501
<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>
503
<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
504
<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>
510
<dt id="simplejson.JSONEncoderForHTML">
511
<!--[simplejson.JSONEncoderForHTML]-->class <tt class="descclassname">simplejson.</tt><tt class="descname">JSONEncoderForHTML</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.JSONEncoderForHTML" title="Permalink to this definition">¶</a></dt>
512
<dd><p>Subclass of <a title="simplejson.JSONEncoder" class="reference internal" href="#simplejson.JSONEncoder"><tt class="xref docutils literal"><span class="pre">JSONEncoder</span></tt></a> that escapes &, <, and > for embedding in HTML.</p>
514
<span class="versionmodified">Changed in version 2.1.0: </span>New in 2.1.0</p>
524
<div class="sphinxsidebar">
525
<div class="sphinxsidebarwrapper">
526
<h3>Table Of Contents</h3>
528
<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">simplejson</span></tt> — JSON encoder and decoder</a><ul>
529
<li><a class="reference external" href="#basic-usage">Basic Usage</a></li>
530
<li><a class="reference external" href="#encoders-and-decoders">Encoders and decoders</a></li>
536
<ul class="this-page-menu">
537
<li><a href="_sources/index.txt">Show Source</a></li>
539
<h3>Quick search</h3>
540
<form class="search" action="search.html" method="get">
541
<input type="text" name="q" size="18" /> <input type="submit" value="Go" />
542
<input type="hidden" name="check_keywords" value="yes" />
543
<input type="hidden" name="area" value="default" />
547
<div class="clearer"></div>
549
<div class="related">
552
<li class="right" style="margin-right: 10px">
553
<a href="genindex.html" title="General Index"
554
accesskey="I">index</a></li>
555
<li><a href="">simplejson v2.1.1 documentation</a> »</li>
559
© Copyright 2008, Bob Ippolito.
560
Last updated on Mar 31, 2010.
561
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
b'\\ No newline at end of file'