JSON library ‘Struson’ version 0.4.0 released; new simpler API

I have released version 0.4.0 of my low-level streaming JSON library called 'Struson'. It is still experimental, but any feedback and suggestions regarding API and implementation are welcome!

An interesting use case for Struson came up in this discussion where a user was asking for reading partial / cut-off JSON data. And it seems Struson is suitable for that; just in case that is useful for you as well.

Based on the feedback on my previous post for the last version I have added a new experimental 'simple API' now. Compared to the existing 'advanced' API it enforces correct usage at compile time, reducing the risk of panics at runtime due to incorrect API usage.

The entrypoints for the simple API are SimpleJsonReader and SimpleJsonWriter; it is currently guarded by the experimental feature. Here are some examples:


use struson::reader::simple::*;

// In this example JSON data comes from a string;
// normally it would come from a file or a network connection
let json_reader = SimpleJsonReader::new(r#"["a", "short", "example"]"#.as_bytes());
let mut words = Vec::<String>::new();
json_reader.read_array_items(|item_reader| {
    let word = item_reader.read_string()?;
assert_eq!(words, vec!["a", "short", "example"]);


use struson::writer::simple::*;

// In this example JSON bytes are stored in a Vec;
// normally they would be written to a file or network connection
let mut writer = Vec::<u8>::new();
let json_writer = SimpleJsonWriter::new(&mut writer);
json_writer.write_object(|object_writer| {
    object_writer.write_number_member("a", 1)?;
    object_writer.write_bool_member("b", true)?;

let json = String::from_utf8(writer)?;
assert_eq!(json, r#"{"a":1,"b":true}"#);

Similar to the 'advanced API' the 'simple API' also has optional Serde integration support through read_deserialize and write_serialize.

Any feedback is highly appreciated! You can either provide it here, or for the 'simple API' you can also provide it on this GitHub issue.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.