Giter Site home page Giter Site logo

simple-json2's Introduction

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

simple-json2's People

Contributors

jimmychu0807 avatar xlc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.