Giter Site home page Giter Site logo

qjson's Introduction

The qJSON-parser

A quick and easy JSON parser.

โš  WARNING: This library should not be used in production, it is purely for learning rust and how its library system works.

Introduction

This is a simple JSON parser written in Rust with full support for JSON5 serialization and deserialization.

Usage

The following code snippet shows an example of how to use the parser:

use qjson::{parse_file, parse_str};

fn main() {
    let json = r#"{
        name: "John Doe",
        'age': 42,
        "married": true,
        "children": ['Jane', "Jack"],
        "address": {
            "street": "Main St.",
            "city": "New York",
            "state": "NY"
        }
    }"#;

    let parsed = parse_str(json).unwrap();
    println!("{:?}", parsed);
}

The output is the parsed JSON object:

{
    "name": "John Doe",
    "age": 42,
    "married": true,
    "children": [
        "Jane",
        "Jack"
    ],
    "address": {
        "street": "Main St.",
        "city": "New York",
        "state": "NY"
    }
}

Features

The following features are provided by the library.

Definition

JSON values and numerical values are defined as following:

#[derive(Debug, PartialEq, Clone)]
pub enum JsonNumber {
    Int(i64),
    Float(f64),
}

#[derive(Debug, PartialEq, Clone)]
pub enum JsonValue {
 Null,
 Bool(bool),
 Number(JsonNumber),
 String(String),
 Array(Vec<Box<JsonValue>>),
 Object(HashMap<String, Box<JsonValue>>),
}

Single values

It is also possible to parse single JSON values:

use qjson::{parse_str};

fn main() {
    let json = r#"[1, 2, 3]"#;
    let parsed = parse_str(json).unwrap();
    println!("{:?}", parsed);
}

The output is the parsed JSON array:

[ 1, 2, 3 ]

qjson's People

Contributors

williamragstad avatar

Watchers

James Cloos 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.