Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

kson πŸ¦€

The name comes from Krab + JSON β€” a JSON-to-Rust-struct parser (and back), built as a learning project.

kson is a Rust library for parsing JSON into native Rust types and serializing Rust types back into JSON, implemented from scratch (no serde) as an exercise to really understand tokenizers, parsers, and error handling in Rust.

Why?

This project isn't trying to replace serde_json (which is excellent and highly optimized) β€” it's a hands-on exercise to learn:

  • How a tokenizer/lexer works
  • Recursive-descent parsers
  • Designing types with enum to represent arbitrary data (AST)
  • Idiomatic error handling in Rust
  • (Optional, future) Derive macros with proc_macro2 / syn / quote

Project status

🚧 Actively in development β€” personal learning project, not recommended for production use.

Installation

Since this is a local/personal crate, add it to your Cargo.toml:

[dependencies]
kson = { path = "../kson" }

Basic usage

use kson::JsonValue;

fn main() {
    let input = r#"{"name": "RamΓ³n", "active": true, "age": 28}"#;

    let value = kson::parse(input).expect("Invalid JSON");

    match value {
        JsonValue::Object(map) => {
            println!("Parsed {} fields", map.len());
        }
        _ => println!("Not an object"),
    }

    let back_to_string = kson::to_string(&value);
    println!("{}", back_to_string);
}

Supported types

  • null
  • bool (true / false)
  • Numbers (f64)
  • Strings
  • Arrays (Vec<JsonValue>)
  • Objects (HashMap<String, JsonValue>)

Roadmap

  • Basic tokenizer
  • Recursive-descent parser β†’ JsonValue
  • JsonValue β†’ String serialization
  • Error handling with position (line/column)
  • Derive macros (#[derive(ToJson)], #[derive(FromJson)])
  • Benchmarks against serde_json

License

MIT β€” personal learning project.

About

(WIP) kson β€” a Krab-inspired JSON parser/serializer for Rust, built from scratch (no serde). πŸ¦€

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages