simple_json 0.2.3

A simple runtime JSON parser.
Documentation
  • Coverage
  • 0%
    0 out of 15 items documented0 out of 0 items with examples
  • Size
  • Source code size: 38.77 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.75 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Rafagd/json-rs
    7 3 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Rafagd

Runtime JSON parser for Rust

crates.io travis-ci coveralls

simple_json is a JSON run-time recursive parser created for simplyfing both reading and writing JSON-encoded data. It's also supposed to be compatible with the current stable release so if you detect any problems, please report them.

Although I believe this package runs fast enough for most cases, it wasn't made with performance or big data sets in mind. In those cases you may be better using Serde instead.

This package abuses Rust's Option feature and creates a tree, where all nodes fit into one of 6 types:

  • Json::Object(HashMap<String, Json>)
  • Json::Array(Vec<Json>)
  • Json::String(String)
  • Json::Number(simple_json::Number)
  • Json::Boolean(bool)
  • Json::Null

All of them implement the From trait in both ways, so converting between them and their native counterparts should be as easy as calling into().

Number is another enum created to represent the multiple different types a JSON Number can hold. The parser will try to choose the most sensible type for each situation, so this should be transparent to user.

A Number can be one of 3 types:

  • Number::Float(f64), if its a floating number (ie. 3.2) or if its written in scientific notation (ie. 3e2);
  • Number::Integer(i64), if the parser receives a signed number (ie. -1);
  • Number::Unsigned(u64), for everything else (ie. 42).

Here's a simple example:

extern crate simple_json;

use simple_json::Json;

fn main() {
    let mut text = "{ \"integer\": 12, \"float\": 80.5, \"string\": \"A JSON sample\", \"array\": [ 1, 2, 3 ], \"object\": { \"a\": \"b\" } }";
    let result = Json::parse(text).unwrap();
    
    println!("Result: {}", result.to_string());
}

Output:

Result: {
  "integer": 12,
  "float":   80.5,
  "string":  "A JSON sample",
  "array": [ 1, 2, 3 ],
  "object": {
    "a": "b"
  }
}