3 stable releases

1.0.2 Jul 6, 2019

#2304 in Parser implementations

Download history 1/week @ 2023-11-20 6/week @ 2023-11-27 1/week @ 2024-01-15 5/week @ 2024-01-29 4/week @ 2024-02-12 25/week @ 2024-02-19 46/week @ 2024-02-26 23/week @ 2024-03-04

98 downloads per month

MIT license

14KB
343 lines

json-parser

JSON tokenizer and parser. JSON format supports following types:

  • Number, translates to Rust f68
  • String, translates to Rust owned String
  • Null, doesnt have a direct translation in Rust, indicates absence of value
  • Array, roughly tranlates to Vec<T>, where T is one of the listed types
  • Object, roughly translates to HashMap<String, T>, where T is one of the listed types

JSON value

is defined as follows:

pub enum Json {
 Null,
 Bool(bool),
 Number(f64),
 String(String),
 Array(Vec<Box<Json>>),
 Object(HashMap<String, Box<Json>>),
}

This enum implements FromStr trait and therefore can be used as follows:

let value: Json = json_string.parse::<Json>()?;

install

Add to your Cargo.toml

json-parser = "1"

Dependencies

~2–3MB
~53K SLoC