xur_

> module

std::json

JSON serialisation

use std::json; feature json in the browser

std::json parses JSON text into Xur values and serialises Xur values back to JSON. Objects become records, arrays become lists, numbers become integers or floats, strings remain strings, booleans remain booleans, and null becomes None. Parsing and serialising don't round-trip None exactly; see stringify.

> functions

# parse(text: str) -> Result<any, str>

Parses JSON text into a Xur value, or returns Err with the parser's message.

# stringify(value: any) -> Result<str, str>

Serialises value as compact JSON. Records, structs and enum variants become objects keyed by field name, with tuple fields named by position, so Some(3) gives {"0":3} and None gives {}. Lists and tuples become arrays, bytes an array of numbers, and () becomes null. Functions, modules and native objects can't be serialised and give Err.

> examples

use std::json;
use std::io;

fn main() -> Result<()> {
    let data = json::parse("{\"name\": \"xur\", \"version\": 1}")?;
    io::println("name: {}", data.name);
    io::println("{}", json::stringify(data)?);
    Ok(())
}