Crate nyoom_json

Crate nyoom_json 

Source
Expand description

§nyoom-json : json what goes nyoom

nyoom-json is a bare-bones streaming json generation library, built for specialized use cases and Just Going Fast :tm: it’s also no-std!

§credit where credit is due

nyoom-json borrows heavily in style from write-json, and takes its string escaping code from miniserde

§examples

use nyoom_json::{Serializer, Null};
let mut out = String::new();
let mut ser = Serializer::new(&mut out);

let mut obj = ser.object();
obj.field("kind", "cat");
obj.field("has_been_fed", false);
obj.field("meow_decibels", 45);
obj.field("illness", Null); // good! mew :3
obj.end();
use nyoom_json::Serializer;
let mut out = String::new();
let mut ser = Serializer::new(&mut out);

let mut arr = ser.array();
arr.add(1);
arr.add(2);
arr.add("three");
arr.end();

ser.end();
use nyoom_json::{Serializer, UnescapedStr};
let mut out = String::with_capacity(64);
let mut ser = Serializer::new(&mut out);
let mut arr = ser.array();
    
arr.add_complex(|mut ser| {
    let mut state = ser.object();
    state.field(UnescapedStr::create("mew"), 3);
    state.complex_field(UnescapedStr::create("meow"), |mut ser| {
        let mut seq = ser.array();
        seq.add(3);
        seq.add(2);
    });
});
arr.add("ny");
arr.end();

Structs§

ArrayWriter
Serializer for a JSON array.
Null
The JSON null value!
ObjectWriter
A serializer for a JSON object.
Serializer
A general JSON serializer, over a mutable buffer of some sort.
SingleValueSerializer
A serializer that is only able to serialize a single value. See documentation of Serializer
UnescapedStr
A string that will not have escapes applied to it. You should only use this if you’re absolutely sure you don’t need them.

Traits§

JsonBuffer
Any buffer which JSON may be written into.
Key
A key for a JSON object’s field.
WriteToJson
A value that is able to be written directly into JSON.