#serialization #json #bson #format-json #data-interchange #binary

no-std nson

NSON is a lightweight data-interchange format like JSON or BSON

38 releases

0.14.0-rc2 Apr 22, 2024
0.12.1 Jun 29, 2021
0.11.0 Oct 5, 2020
0.8.4 Jun 9, 2020
0.1.0 Dec 13, 2017

#280 in Encoding

Download history 13/week @ 2024-02-26 4/week @ 2024-03-11 85/week @ 2024-04-01 38/week @ 2024-04-08 36/week @ 2024-04-15 91/week @ 2024-04-22

250 downloads per month
Used in 3 crates

MIT license

115KB
3.5K SLoC

nson

crates.io docs.rs crates.io

NSON is short for NEW JSON, a binary encoded serialization of JSON-like documents. Similar to JSON, NSON supports embedding maps and arrays within other maps and arrays. Unlike JSON, NSON also includes int32/uint32, int64/uint64, f32/f64, binary, timestamp, id types.

NSON borrows from BSON and can be thought of as a streamlined version of BSON, removing some of the less common or mongodb-proprietary types. NSON also categorizes Double into f32 and f64, considering that f64 is not needed in most cases for high-precision floating-point numbers. Also added uint32 and uint64 to make it clear that values cannot be complex.

In the rust language, NSON can be easily written without necessarily serializing/unserializing to structures, thanks to the macro.

In addition, NSON is convenient to parse from binary, and the library implements "no_std", which can be used on microcontrollers.

Example

use nson::m;

fn main() {
    let mut value = m!{
        "code": 200,
        "success": true,
        "payload": {
            "some": [
                "pay",
                "loads",
            ]
        }
    };

    println!("{:?}", value);
    // print: Map{"code": I32(200), "success": Bool(true), "payload":
    // Map{"some": Array([String("pay"), String("loads")])}}

    println!("{:?}", value.get("code"));
    // print: Some(I32(200))

    // insert new key, value
    value.insert("hello", "world");

    println!("{:?}", value.get("hello"));
    // print: Some(String("world"))
}

Dependencies

~1.4–2.6MB
~50K SLoC