Crates.io | nyoom-json |
lib.rs | nyoom-json |
version | 0.3.0 |
source | src |
created_at | 2023-05-16 01:18:48.21538 |
updated_at | 2023-05-16 16:28:03.810379 |
description | A json serializer that goes nyoom. |
homepage | |
repository | https://github.com/emily-signet/nyoom-json |
max_upload_size | |
id | 865532 |
size | 244,200 |
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!
nyoom-json borrows heavily in style from write-json, and takes its string escaping code from miniserde
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();