https://github.com/krish120003/jsonparser
JSON parser creating Rust objects in-memory.
https://github.com/krish120003/jsonparser
json parser parsers rust
Last synced: 4 months ago
JSON representation
JSON parser creating Rust objects in-memory.
- Host: GitHub
- URL: https://github.com/krish120003/jsonparser
- Owner: Krish120003
- Created: 2024-05-05T07:51:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-16T16:51:47.000Z (over 1 year ago)
- Last Synced: 2025-04-07T02:44:15.711Z (10 months ago)
- Topics: json, parser, parsers, rust
- Language: Rust
- Homepage:
- Size: 641 KB
- Stars: 22
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jsonparser
A hand written JSON parser in Rust in under 500 lines of code.
This parser reads JSON source from a string and construct a custom JSONValue object in memory.
```rust
enum JSONValue {
Null,
True,
False,
Number(f64),
String(String),
Array(Vec),
Object(HashMap),
}
```
All the source code is in the `src/main.rs` file, including:
- Enum definitions for JSONValue and JSONParseError
- The Parser
- Unit tests
- Quick benchmarks
There is an accompanying blog post for this on my website at [https://krishkrish.com/blog/json-parser-in-rust](https://krishkrish.com/blog/json-parser-in-rust)
## Usage
To use this parser, you can call the `parse` function with a JSON source string.
```rust
let json = r#"
{
"name": "John Doe",
"age": 30,
"is_student": false,
"marks": [90, 80, 85],
"address": {
"street": "123 Main St",
"city": "New York"
}
}
"#;
let json_value = jsonparser::parse(json).unwrap();
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- [JSON.org](https://www.json.org/json-en.html)
- [serde-rs's json-benchmark](https://github.com/serde-rs/json-benchmark/tree/master/data)