index.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `json` mod in crate `rustc_serialize`."><meta name="keywords" content="rust, rustlang, rust-lang, json"><title>rustc_serialize::json - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><link rel="shortcut icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../rustc_serialize/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a><p class='location'>Module json</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li><li><a href="#types">Type Definitions</a></li></ul></div><p class='location'><a href='../index.html'>rustc_serialize</a></p><script>window.sidebarCurrent = {name: 'json', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><input class="search-input" name="search" autocomplete="off" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='in-band'>Module <a href='../index.html'>rustc_serialize</a>::<wbr><a class="mod" href=''>json</a></span><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../../src/rustc_serialize/json.rs.html#14-3999' title='goto source code'>[src]</a></span></h1><div class='docblock'><p>JSON parsing and serialization</p>
  2. <h1 id="what-is-json" class="section-header"><a href="#what-is-json">What is JSON?</a></h1>
  3. <p>JSON (JavaScript Object Notation) is a way to write data in Javascript.
  4. Like XML, it allows encoding structured data in a text format that can be
  5. easily read by humans. Its simple syntax and native compatibility with
  6. JavaScript have made it a widely used format.</p>
  7. <p>Data types that can be encoded are JavaScript types (see the <code>Json</code> enum
  8. for more details):</p>
  9. <ul>
  10. <li><code>I64</code>: equivalent to rust's <code>i64</code></li>
  11. <li><code>U64</code>: equivalent to rust's <code>u64</code></li>
  12. <li><code>F64</code>: equivalent to rust's <code>f64</code></li>
  13. <li><code>Boolean</code>: equivalent to rust's <code>bool</code></li>
  14. <li><code>String</code>: equivalent to rust's <code>String</code></li>
  15. <li><code>Array</code>: equivalent to rust's <code>Vec&lt;T&gt;</code>, but also allowing objects of
  16. different types in the
  17. same array</li>
  18. <li><code>Object</code>: equivalent to rust's <code>BTreeMap&lt;String, json::Json&gt;</code></li>
  19. <li><code>Null</code></li>
  20. </ul>
  21. <p>An object is a series of string keys mapping to values, in <code>&quot;key&quot;: value</code>
  22. format. Arrays are enclosed in square brackets ([ ... ]) and objects in
  23. curly brackets ({ ... }). A simple JSON document encoding a person,
  24. their age, address and phone numbers could look like</p>
  25. <div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><pre class="rust rust-example-rendered ignore">
  26. {
  27. <span class="string">&quot;FirstName&quot;</span>: <span class="string">&quot;John&quot;</span>,
  28. <span class="string">&quot;LastName&quot;</span>: <span class="string">&quot;Doe&quot;</span>,
  29. <span class="string">&quot;Age&quot;</span>: <span class="number">43</span>,
  30. <span class="string">&quot;Address&quot;</span>: {
  31. <span class="string">&quot;Street&quot;</span>: <span class="string">&quot;Downing Street 10&quot;</span>,
  32. <span class="string">&quot;City&quot;</span>: <span class="string">&quot;London&quot;</span>,
  33. <span class="string">&quot;Country&quot;</span>: <span class="string">&quot;Great Britain&quot;</span>
  34. },
  35. <span class="string">&quot;PhoneNumbers&quot;</span>: [
  36. <span class="string">&quot;+44 1234567&quot;</span>,
  37. <span class="string">&quot;+44 2345678&quot;</span>
  38. ]
  39. }</pre>
  40. <h1 id="rust-type-based-encoding-and-decoding" class="section-header"><a href="#rust-type-based-encoding-and-decoding">Rust Type-based Encoding and Decoding</a></h1>
  41. <p>Rust provides a mechanism for low boilerplate encoding &amp; decoding of values
  42. to and from JSON via the serialization API. To be able to encode a piece
  43. of data, it must implement the <code>rustc_serialize::Encodable</code> trait. To be
  44. able to decode a piece of data, it must implement the
  45. <code>rustc_serialize::Decodable</code> trait. The Rust compiler provides an
  46. annotation to automatically generate the code for these traits:
  47. <code>#[derive(RustcDecodable, RustcEncodable)]</code></p>
  48. <p>The JSON API provides an enum <code>json::Json</code> and a trait <code>ToJson</code> to encode
  49. objects. The <code>ToJson</code> trait provides a <code>to_json</code> method to convert an
  50. object into a <code>json::Json</code> value. A <code>json::Json</code> value can be encoded as a
  51. string or buffer using the functions described above. You can also use the
  52. <code>json::Encoder</code> object, which implements the <code>Encoder</code> trait.</p>
  53. <p>When using <code>ToJson</code>, the <code>Encodable</code> trait implementation is not
  54. mandatory.</p>
  55. <h1 id="examples-of-use" class="section-header"><a href="#examples-of-use">Examples of use</a></h1><h2 id="using-autoserialization" class="section-header"><a href="#using-autoserialization">Using Autoserialization</a></h2>
  56. <p>Create a struct called <code>TestStruct</code> and serialize and deserialize it to and
  57. from JSON using the serialization API, using the derived serialization code.</p>
  58. <pre class="rust rust-example-rendered">
  59. <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
  60. <span class="kw">use</span> <span class="ident">rustc_serialize</span>::<span class="ident">json</span>;
  61. <span class="comment">// Automatically generate `RustcDecodable` and `RustcEncodable` trait</span>
  62. <span class="comment">// implementations</span>
  63. <span class="attribute">#[<span class="ident">derive</span>(<span class="ident">RustcDecodable</span>, <span class="ident">RustcEncodable</span>)]</span>
  64. <span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">TestStruct</span> {
  65. <span class="ident">data_int</span>: <span class="ident">u8</span>,
  66. <span class="ident">data_str</span>: <span class="ident">String</span>,
  67. <span class="ident">data_vector</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">u8</span><span class="op">&gt;</span>,
  68. }
  69. <span class="kw">fn</span> <span class="ident">main</span>() {
  70. <span class="kw">let</span> <span class="ident">object</span> <span class="op">=</span> <span class="ident">TestStruct</span> {
  71. <span class="ident">data_int</span>: <span class="number">1</span>,
  72. <span class="ident">data_str</span>: <span class="string">&quot;homura&quot;</span>.<span class="ident">to_string</span>(),
  73. <span class="ident">data_vector</span>: <span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>],
  74. };
  75. <span class="comment">// Serialize using `json::encode`</span>
  76. <span class="kw">let</span> <span class="ident">encoded</span> <span class="op">=</span> <span class="ident">json</span>::<span class="ident">encode</span>(<span class="kw-2">&amp;</span><span class="ident">object</span>).<span class="ident">unwrap</span>();
  77. <span class="comment">// Deserialize using `json::decode`</span>
  78. <span class="kw">let</span> <span class="ident">decoded</span>: <span class="ident">TestStruct</span> <span class="op">=</span> <span class="ident">json</span>::<span class="ident">decode</span>(<span class="kw-2">&amp;</span><span class="ident">encoded</span>).<span class="ident">unwrap</span>();
  79. }</pre>
  80. <h2 id="using-the-tojson-trait" class="section-header"><a href="#using-the-tojson-trait">Using the <code>ToJson</code> trait</a></h2>
  81. <p>The examples below use the <code>ToJson</code> trait to generate the JSON string,
  82. which is required for custom mappings.</p>
  83. <h3 id="simple-example-of-tojson-usage" class="section-header"><a href="#simple-example-of-tojson-usage">Simple example of <code>ToJson</code> usage</a></h3>
  84. <pre class="rust rust-example-rendered">
  85. <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
  86. <span class="kw">use</span> <span class="ident">rustc_serialize</span>::<span class="ident">json</span>::{<span class="self">self</span>, <span class="ident">ToJson</span>, <span class="ident">Json</span>};
  87. <span class="comment">// A custom data structure</span>
  88. <span class="kw">struct</span> <span class="ident">ComplexNum</span> {
  89. <span class="ident">a</span>: <span class="ident">f64</span>,
  90. <span class="ident">b</span>: <span class="ident">f64</span>,
  91. }
  92. <span class="comment">// JSON value representation</span>
  93. <span class="kw">impl</span> <span class="ident">ToJson</span> <span class="kw">for</span> <span class="ident">ComplexNum</span> {
  94. <span class="kw">fn</span> <span class="ident">to_json</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) <span class="op">-&gt;</span> <span class="ident">Json</span> {
  95. <span class="ident">Json</span>::<span class="ident">String</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}+{}i&quot;</span>, <span class="self">self</span>.<span class="ident">a</span>, <span class="self">self</span>.<span class="ident">b</span>))
  96. }
  97. }
  98. <span class="comment">// Only generate `RustcEncodable` trait implementation</span>
  99. <span class="attribute">#[<span class="ident">derive</span>(<span class="ident">RustcEncodable</span>)]</span>
  100. <span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">ComplexNumRecord</span> {
  101. <span class="ident">uid</span>: <span class="ident">u8</span>,
  102. <span class="ident">dsc</span>: <span class="ident">String</span>,
  103. <span class="ident">val</span>: <span class="ident">Json</span>,
  104. }
  105. <span class="kw">fn</span> <span class="ident">main</span>() {
  106. <span class="kw">let</span> <span class="ident">num</span> <span class="op">=</span> <span class="ident">ComplexNum</span> { <span class="ident">a</span>: <span class="number">0.0001</span>, <span class="ident">b</span>: <span class="number">12.539</span> };
  107. <span class="kw">let</span> <span class="ident">data</span>: <span class="ident">String</span> <span class="op">=</span> <span class="ident">json</span>::<span class="ident">encode</span>(<span class="kw-2">&amp;</span><span class="ident">ComplexNumRecord</span>{
  108. <span class="ident">uid</span>: <span class="number">1</span>,
  109. <span class="ident">dsc</span>: <span class="string">&quot;test&quot;</span>.<span class="ident">to_string</span>(),
  110. <span class="ident">val</span>: <span class="ident">num</span>.<span class="ident">to_json</span>(),
  111. }).<span class="ident">unwrap</span>();
  112. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;data: {}&quot;</span>, <span class="ident">data</span>);
  113. <span class="comment">// data: {&quot;uid&quot;:1,&quot;dsc&quot;:&quot;test&quot;,&quot;val&quot;:&quot;0.0001+12.539i&quot;};</span>
  114. }</pre>
  115. <h3 id="verbose-example-of-tojson-usage" class="section-header"><a href="#verbose-example-of-tojson-usage">Verbose example of <code>ToJson</code> usage</a></h3>
  116. <pre class="rust rust-example-rendered">
  117. <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
  118. <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BTreeMap</span>;
  119. <span class="kw">use</span> <span class="ident">rustc_serialize</span>::<span class="ident">json</span>::{<span class="self">self</span>, <span class="ident">Json</span>, <span class="ident">ToJson</span>};
  120. <span class="comment">// Only generate `Decodable` trait implementation</span>
  121. <span class="attribute">#[<span class="ident">derive</span>(<span class="ident">RustcDecodable</span>)]</span>
  122. <span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">TestStruct</span> {
  123. <span class="ident">data_int</span>: <span class="ident">u8</span>,
  124. <span class="ident">data_str</span>: <span class="ident">String</span>,
  125. <span class="ident">data_vector</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">u8</span><span class="op">&gt;</span>,
  126. }
  127. <span class="comment">// Specify encoding method manually</span>
  128. <span class="kw">impl</span> <span class="ident">ToJson</span> <span class="kw">for</span> <span class="ident">TestStruct</span> {
  129. <span class="kw">fn</span> <span class="ident">to_json</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) <span class="op">-&gt;</span> <span class="ident">Json</span> {
  130. <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">BTreeMap</span>::<span class="ident">new</span>();
  131. <span class="comment">// All standard types implement `to_json()`, so use it</span>
  132. <span class="ident">d</span>.<span class="ident">insert</span>(<span class="string">&quot;data_int&quot;</span>.<span class="ident">to_string</span>(), <span class="self">self</span>.<span class="ident">data_int</span>.<span class="ident">to_json</span>());
  133. <span class="ident">d</span>.<span class="ident">insert</span>(<span class="string">&quot;data_str&quot;</span>.<span class="ident">to_string</span>(), <span class="self">self</span>.<span class="ident">data_str</span>.<span class="ident">to_json</span>());
  134. <span class="ident">d</span>.<span class="ident">insert</span>(<span class="string">&quot;data_vector&quot;</span>.<span class="ident">to_string</span>(), <span class="self">self</span>.<span class="ident">data_vector</span>.<span class="ident">to_json</span>());
  135. <span class="ident">Json</span>::<span class="ident">Object</span>(<span class="ident">d</span>)
  136. }
  137. }
  138. <span class="kw">fn</span> <span class="ident">main</span>() {
  139. <span class="comment">// Serialize using `ToJson`</span>
  140. <span class="kw">let</span> <span class="ident">input_data</span> <span class="op">=</span> <span class="ident">TestStruct</span> {
  141. <span class="ident">data_int</span>: <span class="number">1</span>,
  142. <span class="ident">data_str</span>: <span class="string">&quot;madoka&quot;</span>.<span class="ident">to_string</span>(),
  143. <span class="ident">data_vector</span>: <span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>],
  144. };
  145. <span class="kw">let</span> <span class="ident">json_obj</span>: <span class="ident">Json</span> <span class="op">=</span> <span class="ident">input_data</span>.<span class="ident">to_json</span>();
  146. <span class="kw">let</span> <span class="ident">json_str</span>: <span class="ident">String</span> <span class="op">=</span> <span class="ident">json_obj</span>.<span class="ident">to_string</span>();
  147. <span class="comment">// Deserialize like before</span>
  148. <span class="kw">let</span> <span class="ident">decoded</span>: <span class="ident">TestStruct</span> <span class="op">=</span> <span class="ident">json</span>::<span class="ident">decode</span>(<span class="kw-2">&amp;</span><span class="ident">json_str</span>).<span class="ident">unwrap</span>();
  149. }</pre>
  150. <h2 id="parsing-a-str-to-json-and-reading-the-result" class="section-header"><a href="#parsing-a-str-to-json-and-reading-the-result">Parsing a <code>str</code> to <code>Json</code> and reading the result</a></h2>
  151. <pre class="rust rust-example-rendered">
  152. <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
  153. <span class="kw">use</span> <span class="ident">rustc_serialize</span>::<span class="ident">json</span>::<span class="ident">Json</span>;
  154. <span class="kw">fn</span> <span class="ident">main</span>() {
  155. <span class="kw">let</span> <span class="ident">data</span> <span class="op">=</span> <span class="ident">Json</span>::<span class="ident">from_str</span>(<span class="string">&quot;{\&quot;foo\&quot;: 13, \&quot;bar\&quot;: \&quot;baz\&quot;}&quot;</span>).<span class="ident">unwrap</span>();
  156. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;data: {}&quot;</span>, <span class="ident">data</span>);
  157. <span class="comment">// data: {&quot;bar&quot;:&quot;baz&quot;,&quot;foo&quot;:13}</span>
  158. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;object? {}&quot;</span>, <span class="ident">data</span>.<span class="ident">is_object</span>());
  159. <span class="comment">// object? true</span>
  160. <span class="kw">let</span> <span class="ident">obj</span> <span class="op">=</span> <span class="ident">data</span>.<span class="ident">as_object</span>().<span class="ident">unwrap</span>();
  161. <span class="kw">let</span> <span class="ident">foo</span> <span class="op">=</span> <span class="ident">obj</span>.<span class="ident">get</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">unwrap</span>();
  162. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;array? {:?}&quot;</span>, <span class="ident">foo</span>.<span class="ident">as_array</span>());
  163. <span class="comment">// array? None</span>
  164. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;u64? {:?}&quot;</span>, <span class="ident">foo</span>.<span class="ident">as_u64</span>());
  165. <span class="comment">// u64? Some(13u64)</span>
  166. <span class="kw">for</span> (<span class="ident">key</span>, <span class="ident">value</span>) <span class="kw">in</span> <span class="ident">obj</span>.<span class="ident">iter</span>() {
  167. <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}: {}&quot;</span>, <span class="ident">key</span>, <span class="kw">match</span> <span class="kw-2">*</span><span class="ident">value</span> {
  168. <span class="ident">Json</span>::<span class="ident">U64</span>(<span class="ident">v</span>) <span class="op">=&gt;</span> <span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{} (u64)&quot;</span>, <span class="ident">v</span>),
  169. <span class="ident">Json</span>::<span class="ident">String</span>(<span class="kw-2">ref</span> <span class="ident">v</span>) <span class="op">=&gt;</span> <span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{} (string)&quot;</span>, <span class="ident">v</span>),
  170. <span class="kw">_</span> <span class="op">=&gt;</span> <span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;other&quot;</span>)
  171. });
  172. }
  173. <span class="comment">// bar: baz (string)</span>
  174. <span class="comment">// foo: 13 (u64)</span>
  175. }</pre>
  176. <h1 id="the-status-of-this-library" class="section-header"><a href="#the-status-of-this-library">The status of this library</a></h1>
  177. <p>While this library is the standard way of working with JSON in Rust,
  178. there is a next-generation library called Serde that's in the works (it's
  179. faster, overcomes some design limitations of rustc-serialize and has more
  180. features). You might consider using it when starting a new project or
  181. evaluating Rust JSON performance.</p>
  182. </div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
  183. <table>
  184. <tr class=' module-item'>
  185. <td><a class="struct" href="struct.AsJson.html"
  186. title='struct rustc_serialize::json::AsJson'>AsJson</a></td>
  187. <td class='docblock-short'>
  188. </td>
  189. </tr>
  190. <tr class=' module-item'>
  191. <td><a class="struct" href="struct.AsPrettyJson.html"
  192. title='struct rustc_serialize::json::AsPrettyJson'>AsPrettyJson</a></td>
  193. <td class='docblock-short'>
  194. </td>
  195. </tr>
  196. <tr class=' module-item'>
  197. <td><a class="struct" href="struct.Builder.html"
  198. title='struct rustc_serialize::json::Builder'>Builder</a></td>
  199. <td class='docblock-short'>
  200. <p>A Builder consumes a json::Parser to create a generic Json structure.</p>
  201. </td>
  202. </tr>
  203. <tr class=' module-item'>
  204. <td><a class="struct" href="struct.Decoder.html"
  205. title='struct rustc_serialize::json::Decoder'>Decoder</a></td>
  206. <td class='docblock-short'>
  207. <p>A structure to decode JSON to values in rust.</p>
  208. </td>
  209. </tr>
  210. <tr class=' module-item'>
  211. <td><a class="struct" href="struct.Encoder.html"
  212. title='struct rustc_serialize::json::Encoder'>Encoder</a></td>
  213. <td class='docblock-short'>
  214. <p>A structure for implementing serialization to JSON.</p>
  215. </td>
  216. </tr>
  217. <tr class=' module-item'>
  218. <td><a class="struct" href="struct.Parser.html"
  219. title='struct rustc_serialize::json::Parser'>Parser</a></td>
  220. <td class='docblock-short'>
  221. <p>A streaming JSON parser implemented as an iterator of JsonEvent, consuming
  222. an iterator of char.</p>
  223. </td>
  224. </tr>
  225. <tr class=' module-item'>
  226. <td><a class="struct" href="struct.PrettyJson.html"
  227. title='struct rustc_serialize::json::PrettyJson'>PrettyJson</a></td>
  228. <td class='docblock-short'>
  229. </td>
  230. </tr>
  231. <tr class=' module-item'>
  232. <td><a class="struct" href="struct.Stack.html"
  233. title='struct rustc_serialize::json::Stack'>Stack</a></td>
  234. <td class='docblock-short'>
  235. <p>A Stack represents the current position of the parser in the logical
  236. structure of the JSON stream.
  237. For example foo.bar[3].x</p>
  238. </td>
  239. </tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
  240. <table>
  241. <tr class=' module-item'>
  242. <td><a class="enum" href="enum.DecoderError.html"
  243. title='enum rustc_serialize::json::DecoderError'>DecoderError</a></td>
  244. <td class='docblock-short'>
  245. </td>
  246. </tr>
  247. <tr class=' module-item'>
  248. <td><a class="enum" href="enum.EncoderError.html"
  249. title='enum rustc_serialize::json::EncoderError'>EncoderError</a></td>
  250. <td class='docblock-short'>
  251. </td>
  252. </tr>
  253. <tr class=' module-item'>
  254. <td><a class="enum" href="enum.ErrorCode.html"
  255. title='enum rustc_serialize::json::ErrorCode'>ErrorCode</a></td>
  256. <td class='docblock-short'>
  257. <p>The errors that can arise while parsing a JSON stream.</p>
  258. </td>
  259. </tr>
  260. <tr class=' module-item'>
  261. <td><a class="enum" href="enum.Json.html"
  262. title='enum rustc_serialize::json::Json'>Json</a></td>
  263. <td class='docblock-short'>
  264. <p>Represents a json value</p>
  265. </td>
  266. </tr>
  267. <tr class=' module-item'>
  268. <td><a class="enum" href="enum.JsonEvent.html"
  269. title='enum rustc_serialize::json::JsonEvent'>JsonEvent</a></td>
  270. <td class='docblock-short'>
  271. <p>The output of the streaming parser.</p>
  272. </td>
  273. </tr>
  274. <tr class=' module-item'>
  275. <td><a class="enum" href="enum.ParserError.html"
  276. title='enum rustc_serialize::json::ParserError'>ParserError</a></td>
  277. <td class='docblock-short'>
  278. </td>
  279. </tr>
  280. <tr class=' module-item'>
  281. <td><a class="enum" href="enum.StackElement.html"
  282. title='enum rustc_serialize::json::StackElement'>StackElement</a></td>
  283. <td class='docblock-short'>
  284. <p>StackElements compose a Stack.
  285. For example, Key(&quot;foo&quot;), Key(&quot;bar&quot;), Index(3) and Key(&quot;x&quot;) are the
  286. StackElements compositing the stack that represents foo.bar[3].x</p>
  287. </td>
  288. </tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
  289. <table>
  290. <tr class=' module-item'>
  291. <td><a class="trait" href="trait.ToJson.html"
  292. title='trait rustc_serialize::json::ToJson'>ToJson</a></td>
  293. <td class='docblock-short'>
  294. <p>A trait for converting values to JSON</p>
  295. </td>
  296. </tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
  297. <table>
  298. <tr class=' module-item'>
  299. <td><a class="fn" href="fn.as_json.html"
  300. title='fn rustc_serialize::json::as_json'>as_json</a></td>
  301. <td class='docblock-short'>
  302. <p>Create an <code>AsJson</code> wrapper which can be used to print a value as JSON
  303. on-the-fly via <code>write!</code></p>
  304. </td>
  305. </tr>
  306. <tr class=' module-item'>
  307. <td><a class="fn" href="fn.as_pretty_json.html"
  308. title='fn rustc_serialize::json::as_pretty_json'>as_pretty_json</a></td>
  309. <td class='docblock-short'>
  310. <p>Create an <code>AsPrettyJson</code> wrapper which can be used to print a value as JSON
  311. on-the-fly via <code>write!</code></p>
  312. </td>
  313. </tr>
  314. <tr class=' module-item'>
  315. <td><a class="fn" href="fn.decode.html"
  316. title='fn rustc_serialize::json::decode'>decode</a></td>
  317. <td class='docblock-short'>
  318. <p>Shortcut function to decode a JSON <code>&amp;str</code> into an object</p>
  319. </td>
  320. </tr>
  321. <tr class=' module-item'>
  322. <td><a class="fn" href="fn.encode.html"
  323. title='fn rustc_serialize::json::encode'>encode</a></td>
  324. <td class='docblock-short'>
  325. <p>Shortcut function to encode a <code>T</code> into a JSON <code>String</code></p>
  326. </td>
  327. </tr>
  328. <tr class=' module-item'>
  329. <td><a class="fn" href="fn.error_str.html"
  330. title='fn rustc_serialize::json::error_str'>error_str</a></td>
  331. <td class='docblock-short'>
  332. <p>Returns a readable error string for a given error code.</p>
  333. </td>
  334. </tr></table><h2 id='types' class='section-header'><a href="#types">Type Definitions</a></h2>
  335. <table>
  336. <tr class=' module-item'>
  337. <td><a class="type" href="type.Array.html"
  338. title='type rustc_serialize::json::Array'>Array</a></td>
  339. <td class='docblock-short'>
  340. </td>
  341. </tr>
  342. <tr class=' module-item'>
  343. <td><a class="type" href="type.BuilderError.html"
  344. title='type rustc_serialize::json::BuilderError'>BuilderError</a></td>
  345. <td class='docblock-short'>
  346. </td>
  347. </tr>
  348. <tr class=' module-item'>
  349. <td><a class="type" href="type.DecodeResult.html"
  350. title='type rustc_serialize::json::DecodeResult'>DecodeResult</a></td>
  351. <td class='docblock-short'>
  352. </td>
  353. </tr>
  354. <tr class=' module-item'>
  355. <td><a class="type" href="type.EncodeResult.html"
  356. title='type rustc_serialize::json::EncodeResult'>EncodeResult</a></td>
  357. <td class='docblock-short'>
  358. </td>
  359. </tr>
  360. <tr class=' module-item'>
  361. <td><a class="type" href="type.Object.html"
  362. title='type rustc_serialize::json::Object'>Object</a></td>
  363. <td class='docblock-short'>
  364. </td>
  365. </tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "rustc_serialize";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>