mentat/rustc_serialize/json/index.html
2018-08-22 17:04:13 +00:00

535 lines
No EOL
34 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="../../main.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">
</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>
<h1 id="what-is-json" class="section-header"><a href="#what-is-json">What is JSON?</a></h1>
<p>JSON (JavaScript Object Notation) is a way to write data in Javascript.
Like XML, it allows encoding structured data in a text format that can be
easily read by humans. Its simple syntax and native compatibility with
JavaScript have made it a widely used format.</p>
<p>Data types that can be encoded are JavaScript types (see the <code>Json</code> enum
for more details):</p>
<ul>
<li><code>I64</code>: equivalent to rust's <code>i64</code></li>
<li><code>U64</code>: equivalent to rust's <code>u64</code></li>
<li><code>F64</code>: equivalent to rust's <code>f64</code></li>
<li><code>Boolean</code>: equivalent to rust's <code>bool</code></li>
<li><code>String</code>: equivalent to rust's <code>String</code></li>
<li><code>Array</code>: equivalent to rust's <code>Vec&lt;T&gt;</code>, but also allowing objects of
different types in the
same array</li>
<li><code>Object</code>: equivalent to rust's <code>BTreeMap&lt;String, json::Json&gt;</code></li>
<li><code>Null</code></li>
</ul>
<p>An object is a series of string keys mapping to values, in <code>&quot;key&quot;: value</code>
format. Arrays are enclosed in square brackets ([ ... ]) and objects in
curly brackets ({ ... }). A simple JSON document encoding a person,
their age, address and phone numbers could look like</p>
<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">
{
<span class="string">&quot;FirstName&quot;</span>: <span class="string">&quot;John&quot;</span>,
<span class="string">&quot;LastName&quot;</span>: <span class="string">&quot;Doe&quot;</span>,
<span class="string">&quot;Age&quot;</span>: <span class="number">43</span>,
<span class="string">&quot;Address&quot;</span>: {
<span class="string">&quot;Street&quot;</span>: <span class="string">&quot;Downing Street 10&quot;</span>,
<span class="string">&quot;City&quot;</span>: <span class="string">&quot;London&quot;</span>,
<span class="string">&quot;Country&quot;</span>: <span class="string">&quot;Great Britain&quot;</span>
},
<span class="string">&quot;PhoneNumbers&quot;</span>: [
<span class="string">&quot;+44 1234567&quot;</span>,
<span class="string">&quot;+44 2345678&quot;</span>
]
}</pre>
<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>
<p>Rust provides a mechanism for low boilerplate encoding &amp; decoding of values
to and from JSON via the serialization API. To be able to encode a piece
of data, it must implement the <code>rustc_serialize::Encodable</code> trait. To be
able to decode a piece of data, it must implement the
<code>rustc_serialize::Decodable</code> trait. The Rust compiler provides an
annotation to automatically generate the code for these traits:
<code>#[derive(RustcDecodable, RustcEncodable)]</code></p>
<p>The JSON API provides an enum <code>json::Json</code> and a trait <code>ToJson</code> to encode
objects. The <code>ToJson</code> trait provides a <code>to_json</code> method to convert an
object into a <code>json::Json</code> value. A <code>json::Json</code> value can be encoded as a
string or buffer using the functions described above. You can also use the
<code>json::Encoder</code> object, which implements the <code>Encoder</code> trait.</p>
<p>When using <code>ToJson</code>, the <code>Encodable</code> trait implementation is not
mandatory.</p>
<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>
<p>Create a struct called <code>TestStruct</code> and serialize and deserialize it to and
from JSON using the serialization API, using the derived serialization code.</p>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
<span class="kw">use</span> <span class="ident">rustc_serialize</span>::<span class="ident">json</span>;
<span class="comment">// Automatically generate `RustcDecodable` and `RustcEncodable` trait</span>
<span class="comment">// implementations</span>
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">RustcDecodable</span>, <span class="ident">RustcEncodable</span>)]</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">TestStruct</span> {
<span class="ident">data_int</span>: <span class="ident">u8</span>,
<span class="ident">data_str</span>: <span class="ident">String</span>,
<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>,
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="ident">object</span> <span class="op">=</span> <span class="ident">TestStruct</span> {
<span class="ident">data_int</span>: <span class="number">1</span>,
<span class="ident">data_str</span>: <span class="string">&quot;homura&quot;</span>.<span class="ident">to_string</span>(),
<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>],
};
<span class="comment">// Serialize using `json::encode`</span>
<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>();
<span class="comment">// Deserialize using `json::decode`</span>
<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>();
}</pre>
<h2 id="using-the-tojson-trait" class="section-header"><a href="#using-the-tojson-trait">Using the <code>ToJson</code> trait</a></h2>
<p>The examples below use the <code>ToJson</code> trait to generate the JSON string,
which is required for custom mappings.</p>
<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>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
<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>};
<span class="comment">// A custom data structure</span>
<span class="kw">struct</span> <span class="ident">ComplexNum</span> {
<span class="ident">a</span>: <span class="ident">f64</span>,
<span class="ident">b</span>: <span class="ident">f64</span>,
}
<span class="comment">// JSON value representation</span>
<span class="kw">impl</span> <span class="ident">ToJson</span> <span class="kw">for</span> <span class="ident">ComplexNum</span> {
<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> {
<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>))
}
}
<span class="comment">// Only generate `RustcEncodable` trait implementation</span>
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">RustcEncodable</span>)]</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">ComplexNumRecord</span> {
<span class="ident">uid</span>: <span class="ident">u8</span>,
<span class="ident">dsc</span>: <span class="ident">String</span>,
<span class="ident">val</span>: <span class="ident">Json</span>,
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<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> };
<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>{
<span class="ident">uid</span>: <span class="number">1</span>,
<span class="ident">dsc</span>: <span class="string">&quot;test&quot;</span>.<span class="ident">to_string</span>(),
<span class="ident">val</span>: <span class="ident">num</span>.<span class="ident">to_json</span>(),
}).<span class="ident">unwrap</span>();
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;data: {}&quot;</span>, <span class="ident">data</span>);
<span class="comment">// data: {&quot;uid&quot;:1,&quot;dsc&quot;:&quot;test&quot;,&quot;val&quot;:&quot;0.0001+12.539i&quot;};</span>
}</pre>
<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>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">BTreeMap</span>;
<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>};
<span class="comment">// Only generate `Decodable` trait implementation</span>
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">RustcDecodable</span>)]</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">TestStruct</span> {
<span class="ident">data_int</span>: <span class="ident">u8</span>,
<span class="ident">data_str</span>: <span class="ident">String</span>,
<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>,
}
<span class="comment">// Specify encoding method manually</span>
<span class="kw">impl</span> <span class="ident">ToJson</span> <span class="kw">for</span> <span class="ident">TestStruct</span> {
<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> {
<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>();
<span class="comment">// All standard types implement `to_json()`, so use it</span>
<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>());
<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>());
<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>());
<span class="ident">Json</span>::<span class="ident">Object</span>(<span class="ident">d</span>)
}
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="comment">// Serialize using `ToJson`</span>
<span class="kw">let</span> <span class="ident">input_data</span> <span class="op">=</span> <span class="ident">TestStruct</span> {
<span class="ident">data_int</span>: <span class="number">1</span>,
<span class="ident">data_str</span>: <span class="string">&quot;madoka&quot;</span>.<span class="ident">to_string</span>(),
<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>],
};
<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>();
<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>();
<span class="comment">// Deserialize like before</span>
<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>();
}</pre>
<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>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rustc_serialize</span>;
<span class="kw">use</span> <span class="ident">rustc_serialize</span>::<span class="ident">json</span>::<span class="ident">Json</span>;
<span class="kw">fn</span> <span class="ident">main</span>() {
<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>();
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;data: {}&quot;</span>, <span class="ident">data</span>);
<span class="comment">// data: {&quot;bar&quot;:&quot;baz&quot;,&quot;foo&quot;:13}</span>
<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>());
<span class="comment">// object? true</span>
<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>();
<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>();
<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>());
<span class="comment">// array? None</span>
<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>());
<span class="comment">// u64? Some(13u64)</span>
<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>() {
<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> {
<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>),
<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>),
_ <span class="op">=&gt;</span> <span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;other&quot;</span>)
});
}
<span class="comment">// bar: baz (string)</span>
<span class="comment">// foo: 13 (u64)</span>
}</pre>
<h1 id="the-status-of-this-library" class="section-header"><a href="#the-status-of-this-library">The status of this library</a></h1>
<p>While this library is the standard way of working with JSON in Rust,
there is a next-generation library called Serde that's in the works (it's
faster, overcomes some design limitations of rustc-serialize and has more
features). You might consider using it when starting a new project or
evaluating Rust JSON performance.</p>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table>
<tr class=' module-item'>
<td><a class="struct" href="struct.AsJson.html"
title='struct rustc_serialize::json::AsJson'>AsJson</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.AsPrettyJson.html"
title='struct rustc_serialize::json::AsPrettyJson'>AsPrettyJson</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Builder.html"
title='struct rustc_serialize::json::Builder'>Builder</a></td>
<td class='docblock-short'>
<p>A Builder consumes a json::Parser to create a generic Json structure.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Decoder.html"
title='struct rustc_serialize::json::Decoder'>Decoder</a></td>
<td class='docblock-short'>
<p>A structure to decode JSON to values in rust.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Encoder.html"
title='struct rustc_serialize::json::Encoder'>Encoder</a></td>
<td class='docblock-short'>
<p>A structure for implementing serialization to JSON.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Parser.html"
title='struct rustc_serialize::json::Parser'>Parser</a></td>
<td class='docblock-short'>
<p>A streaming JSON parser implemented as an iterator of JsonEvent, consuming
an iterator of char.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.PrettyJson.html"
title='struct rustc_serialize::json::PrettyJson'>PrettyJson</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Stack.html"
title='struct rustc_serialize::json::Stack'>Stack</a></td>
<td class='docblock-short'>
<p>A Stack represents the current position of the parser in the logical
structure of the JSON stream.
For example foo.bar[3].x</p>
</td>
</tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table>
<tr class=' module-item'>
<td><a class="enum" href="enum.DecoderError.html"
title='enum rustc_serialize::json::DecoderError'>DecoderError</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.EncoderError.html"
title='enum rustc_serialize::json::EncoderError'>EncoderError</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.ErrorCode.html"
title='enum rustc_serialize::json::ErrorCode'>ErrorCode</a></td>
<td class='docblock-short'>
<p>The errors that can arise while parsing a JSON stream.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.Json.html"
title='enum rustc_serialize::json::Json'>Json</a></td>
<td class='docblock-short'>
<p>Represents a json value</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.JsonEvent.html"
title='enum rustc_serialize::json::JsonEvent'>JsonEvent</a></td>
<td class='docblock-short'>
<p>The output of the streaming parser.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.ParserError.html"
title='enum rustc_serialize::json::ParserError'>ParserError</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.StackElement.html"
title='enum rustc_serialize::json::StackElement'>StackElement</a></td>
<td class='docblock-short'>
<p>StackElements compose a Stack.
For example, Key(&quot;foo&quot;), Key(&quot;bar&quot;), Index(3) and Key(&quot;x&quot;) are the
StackElements compositing the stack that represents foo.bar[3].x</p>
</td>
</tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
<table>
<tr class=' module-item'>
<td><a class="trait" href="trait.ToJson.html"
title='trait rustc_serialize::json::ToJson'>ToJson</a></td>
<td class='docblock-short'>
<p>A trait for converting values to JSON</p>
</td>
</tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table>
<tr class=' module-item'>
<td><a class="fn" href="fn.as_json.html"
title='fn rustc_serialize::json::as_json'>as_json</a></td>
<td class='docblock-short'>
<p>Create an <code>AsJson</code> wrapper which can be used to print a value as JSON
on-the-fly via <code>write!</code></p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.as_pretty_json.html"
title='fn rustc_serialize::json::as_pretty_json'>as_pretty_json</a></td>
<td class='docblock-short'>
<p>Create an <code>AsPrettyJson</code> wrapper which can be used to print a value as JSON
on-the-fly via <code>write!</code></p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.decode.html"
title='fn rustc_serialize::json::decode'>decode</a></td>
<td class='docblock-short'>
<p>Shortcut function to decode a JSON <code>&amp;str</code> into an object</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.encode.html"
title='fn rustc_serialize::json::encode'>encode</a></td>
<td class='docblock-short'>
<p>Shortcut function to encode a <code>T</code> into a JSON <code>String</code></p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.error_str.html"
title='fn rustc_serialize::json::error_str'>error_str</a></td>
<td class='docblock-short'>
<p>Returns a readable error string for a given error code.</p>
</td>
</tr></table><h2 id='types' class='section-header'><a href="#types">Type Definitions</a></h2>
<table>
<tr class=' module-item'>
<td><a class="type" href="type.Array.html"
title='type rustc_serialize::json::Array'>Array</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="type" href="type.BuilderError.html"
title='type rustc_serialize::json::BuilderError'>BuilderError</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="type" href="type.DecodeResult.html"
title='type rustc_serialize::json::DecodeResult'>DecodeResult</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="type" href="type.EncodeResult.html"
title='type rustc_serialize::json::EncodeResult'>EncodeResult</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="type" href="type.Object.html"
title='type rustc_serialize::json::Object'>Object</a></td>
<td class='docblock-short'>
</td>
</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>
</div>
</div>
</aside>
<script>
window.rootPath = "../../";
window.currentCrate = "rustc_serialize";
</script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>