json

JSON implementation in Rust

Latest version: 0.12.4 registry icon
Maintenance score
0
Safety score
0
Popularity score
78
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.12.4 0 0 1 0 0
0.12.3 0 0 1 0 0
0.12.2 0 0 1 0 0
0.12.1 0 0 1 0 0
0.12.0 0 0 1 0 0
0.11.15 0 0 1 0 0
0.11.14 0 0 1 0 0
0.11.13 0 0 1 0 0
0.11.12 0 0 1 0 0
0.11.11 0 0 1 0 0
0.11.10 0 0 1 0 0
0.11.9 0 0 1 0 0
0.11.8 0 0 1 0 0
0.11.7 0 0 1 0 0
0.11.6 0 0 1 0 0
0.11.5 0 0 1 0 0
0.11.4 0 0 1 0 0
0.11.3 0 0 1 0 0
0.11.2 0 0 1 0 0
0.11.1 0 0 1 0 0
0.11.0 0 0 1 0 0
0.10.3 0 0 1 0 0
0.10.2 0 0 1 0 0
0.10.1 0 0 1 0 0
0.10.0 0 0 1 0 0
0.9.1 0 0 1 0 0
0.9.0 0 0 1 0 0
0.8.8 0 0 1 0 0
0.8.7 0 0 1 0 0
0.8.6 0 0 1 0 0
0.8.5 0 0 1 0 0
0.8.4 0 0 1 0 0
0.8.2 0 0 1 0 0
0.8.1 0 0 1 0 0
0.8.0 0 0 1 0 0
0.7.4 0 0 1 0 0
0.7.3 0 0 1 0 0
0.7.2 0 0 1 0 0
0.7.1 0 0 1 0 0
0.7.0 0 0 1 0 0
0.6.1 0 0 1 0 0
0.6.0 0 0 1 0 0
0.5.1 0 0 1 0 0
0.5.0 0 0 1 0 0
0.4.0 0 0 1 0 0
0.3.4 0 0 1 0 0
0.3.3 0 0 1 0 0
0.3.2 0 0 1 0 0
0.3.1 0 0 1 0 0
0.3.0 0 0 1 0 0
0.2.1 0 0 1 0 0
0.2.0 0 0 1 0 0
0.1.1 0 0 1 0 0
0.1.0 0 0 1 0 0

Stability
Latest release:

0.12.4 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

Apache-2.0   -   Apache License 2.0

Not a wildcard

Not proprietary

OSI Compliant


MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



json-rust

Parse and serialize JSON with ease.

Changelog - Complete Documentation - Cargo - Repository

Why?

JSON is a very loose format where anything goes - arrays can hold mixed types, object keys can change types between API calls or not include some keys under some conditions. Mapping that to idiomatic Rust structs introduces friction.

This crate intends to avoid that friction.

let parsed = json::parse(r#"

{
    "code": 200,
    "success": true,
    "payload": {
        "features": [
            "awesome",
            "easyAPI",
            "lowLearningCurve"
        ]
    }
}

"#).unwrap();

let instantiated = object!{
    // quotes on keys are optional
    "code": 200,
    success: true,
    payload: {
        features: [
            "awesome",
            "easyAPI",
            "lowLearningCurve"
        ]
    }
};

assert_eq!(parsed, instantiated);

First class citizen

Using macros and indexing, it's easy to work with the data.

let mut data = object!{
    foo: false,
    bar: null,
    answer: 42,
    list: [null, "world", true]
};

// Partial equality is implemented for most raw types:
assert!(data["foo"] == false);

// And it's type aware, `null` and `false` are different values:
assert!(data["bar"] != false);

// But you can use any Rust number types:
assert!(data["answer"] == 42);
assert!(data["answer"] == 42.0);
assert!(data["answer"] == 42isize);

// Access nested structures, arrays and objects:
assert!(data["list"][0].is_null());
assert!(data["list"][1] == "world");
assert!(data["list"][2] == true);

// Error resilient - accessing properties that don't exist yield null:
assert!(data["this"]["does"]["not"]["exist"].is_null());

// Mutate by assigning:
data["list"][0] = "Hello".into();

// Use the `dump` method to serialize the data:
assert_eq!(data.dump(), r#"{"foo":false,"bar":null,"answer":42,"list":["Hello","world",true]}"#);

// Or pretty print it out:
println!("{:#}", data);

Installation

Just add it to your Cargo.toml file:

[dependencies]
json = "*"

Then import it in your main.rs / lib.rs file:

#[macro_use]
extern crate json;

Performance and Conformance

There used to be a statement here saying that performance is not the main goal of this crate. It is definitely one of them now.

While this crate doesn't provide a way to parse JSON to native Rust structs, it does a lot to optimize its performance for DOM parsing, stringifying and manipulation. It does very well in benchmarks, in some cases it can even outperform parsing to structs.

This crate implements the standard according to the RFC 7159 and ECMA-404 documents. For the best interoperability numbers are treated stored as 64bit precision mantissa with 16 bit decimal exponent for floating point representation.

License

This crate is distributed under the terms of both the MIT license and the Apache License (Version 2.0). Choose whichever one works best for you.

See LICENSE-APACHE and LICENSE-MIT for details.