simple-json2 0.1.2

Simple JSON parser. Wasm / no_std ready.
Documentation
  • Coverage
  • 0%
    0 out of 126 items documented0 out of 67 items with examples
  • Size
  • Source code size: 37.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 13.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jimmychu0807

simple-json2

Simple JSON parser written with Rust. Wasm / no_std ready.

# Build this project in `no_std` env:
just build

# Running test in `no_std` env:
just test

# Run this project in cli (a sample for parsing) in `std` env:
just run

Usage

To parse a string into JSON object

use simple_json2::{ self, parse_json, impls::SimpleError };

fn parse_simple() -> Result<(), SimpleError> {
	let json_str = r#"{"data":{"id":"bitcoin","symbol":"BTC"},"timestamp":1574224303089}"#;

	// To parse a string to JSON object

	let json: JsonValue = parse_json(&json_str)?;

	// To get a value out from the JSON object

	let json_obj = &json.get_object()?[0];

	// We use vec of char because in `no_std` env, there is no `String`
	assert_eq!(json_obj.0, "data".chars().collect::<Vec<char>>());

	let inner_obj = &json_obj.1.get_object()?[0];

	assert_eq!(inner_obj.0, "id".chars().collect::<Vec<char>>());
	// If we are in `std` env, we can retrieve value back as `String`
	assert_eq!(inner_obj.1.get_string()?, "bitcoin");

	// -- snip
}

Acknowledgement

This project is derived from xlc/lite-json