| Crates.io | toon-core |
| lib.rs | toon-core |
| version | 0.2.2 |
| created_at | 2025-12-19 18:05:15.853753+00 |
| updated_at | 2025-12-24 23:09:47.887+00 |
| description | Core serialization/parsing logic for TOON-LD format |
| homepage | |
| repository | https://github.com/argahsuknesib/toon-ld |
| max_upload_size | |
| id | 1995212 |
| size | 159,880 |
DEPRECATED: Please use
toon-ldinstead.This crate is no longer maintained. All functionality has been moved to the
toon-ldcrate, which provides a better user-facing API and naming scheme.
Core serialization and parsing logic for the TOON-LD (Token-Oriented Object Notation for Linked Data) format.
This crate provides the fundamental conversion algorithms between JSON-LD and TOON-LD formats, achieving 40-60% token reduction while maintaining full semantic compatibility with JSON-LD.
Add this to your Cargo.toml:
[dependencies]
toon-core = "0.2"
use toon_core::{encode, decode};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Convert JSON-LD to TOON-LD
let json_ld = r#"{
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
"foaf:name": "Alice"
}"#;
let toon = encode(json_ld)?;
println!("TOON-LD:\n{}", toon);
// Convert back to JSON-LD
let back_to_json = decode(&toon)?;
println!("JSON-LD:\n{}", back_to_json);
Ok(())
}
TOON-LD's key feature is efficient serialization of arrays of objects:
use toon_core::encode;
let json_ld = r#"{
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
"@graph": [
{"@id": "ex:1", "foaf:name": "Alice", "foaf:age": 30},
{"@id": "ex:2", "foaf:name": "Bob", "foaf:age": 25}
]
}"#;
let toon = encode(json_ld)?;
// Output uses tabular format:
// @graph[2]{@id,foaf:age,foaf:name}:
// ex:1, 30, Alice
// ex:2, 25, Bob
encode(json: &str) -> Result<String, ToonError> - Convert (encode) JSON-LD to TOON-LDdecode(toon: &str) -> Result<String, ToonError> - Convert (decode) TOON-LD to JSON-LDToonParser::parse(toon: &str) -> Result<Value, ToonError> - Parse TOON-LD to serde_json::ValueToonSerializer::serialize(value: &Value) -> Result<String, ToonError> - Serialize Value to TOON-LDAll functions return Result<T, ToonError> where ToonError provides detailed error messages including line numbers and context.
TOON-LD achieves:
For the complete TOON-LD specification, see the main repository.
toon-cli - Command-line tool for TOON-LD conversion and benchmarkingMIT License - See LICENSE for details.