Crate jsmn_rs[][src]

This crate exposes Rustic bindings to a gem of a C library called jsmn. The raw bindings are available in the raw module, which are wrapped in this module.

The jsmn library provides a very simple, fast JSON parser. I see it as a great example of library design- it has two enums, two structs, and two functions, and that is all. Its trivial to use, very fast, and has very few extra features.

This library only exposes a single function, jsmn_parse, because the jsmn_init function is called when you crate a new JsmnParser.

To use this library, simply create a parser using JsmnParser::new() and pass the parser, a JSON string, and a slice of JsmnToks to jsmn_parse. The result will be that the slice will be filled out with tokens defining the starting and ending offset of each JSON token in the given string.

Thats all there is to it! This crate is just intended to make jsmn easy to use in Rust. There are other JSON parsers in Rust, and certainly Serde and HyperJson are great crates, but I though jsmn deserved a place in the Rust ecosystem, so here it is!



This module provides raw bindings to the jsmn library, generated by bindgen. It is not needed for most use cases, as the more Rustic interface is provided.



A JsmnParser is the parser state for the jsmn library.


A JSON token structure, defining which type of JSON object it is, the starting character, ending character, and size in bytes. All offsets are from the start of the parsed string.



Error type from jsmn_parse. These enum values are identical to the jsmn library enum jsmnerr_t, but renamed to match Rust's conventions.


The JSON object type. These enum values are identical to the jsmn library enum jsmntype_t, but renamed to match Rust's conventions.



This function is the core parsing function. It wraps the underlying jsmn_parse function in a more Rustic interface by taking a slice of JsmnTokens, and returning a Result instead of using sentinal values.