Expand description
§TOON-LD
Token-Oriented Object Notation for Linked Data — A compact RDF serialization format that achieves 40-60% token reduction compared to JSON-LD.
This crate provides high-level conversion functions between JSON-LD and TOON-LD formats. TOON-LD extends TOON in the same way that JSON-LD extends JSON: every valid TOON-LD document is also a valid TOON document.
§Quick Start
use toon_ld::{encode, decode};
// 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)?;§Tabular Arrays
TOON-LD’s key feature is efficient serialization of arrays of objects:
use toon_ld::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 with shared headers:
// @graph[2]{@id,foaf:age,foaf:name}:
// ex:1, 30, Alice
// ex:2, 25, Bob§Features
- 40-60% token reduction compared to JSON-LD
- Full JSON-LD compatibility with round-trip conversion
- Tabular arrays for efficient serialization of uniform data
- Context support for URI compaction
- Value nodes with language tags and datatypes
- Optimized parsing with automatic tabular array detection
Modules§
- context
- JSON-LD Context handling for TOON-LD.
- error
- Error types for TOON-LD operations.
- keywords
- JSON-LD keyword constants for TOON-LD.
- parser
- TOON-LD Parser
- serializer
- TOON-LD Serializer
Structs§
- Json
LdContext - JSON-LD context for prefix expansion/compaction.
- Toon
Parser - TOON-LD Parser
- Toon
Serializer - TOON-LD Serializer
Enums§
Constants§
- JSONLD_
BASE - The
@basekeyword sets the base IRI for relative IRIs - JSONLD_
CONTAINER - The
@containerkeyword specifies how values are organized - JSONLD_
CONTEXT - The
@contextkeyword defines the vocabulary mapping for terms - JSONLD_
DIRECTION - The
@directionkeyword specifies text direction (ltr/rtl) - JSONLD_
GRAPH - The
@graphkeyword contains a named graph - JSONLD_
ID - The
@idkeyword identifies a node with an IRI - JSONLD_
IMPORT - The
@importkeyword imports an external context - JSONLD_
INCLUDED - The
@includedkeyword specifies included nodes - JSONLD_
INDEX - The
@indexkeyword specifies an index value for a node - JSONLD_
JSON - The
@jsonkeyword marks a JSON literal value - JSONLD_
LANGUAGE - The
@languagekeyword specifies the language of a string value - JSONLD_
LIST - The
@listkeyword specifies an ordered list - JSONLD_
NEST - The
@nestkeyword specifies nested properties - JSONLD_
NONE - The
@nonekeyword represents the default index value - JSONLD_
PREFIX - The
@prefixkeyword indicates a term is a prefix - JSONLD_
PROPAGATE - The
@propagatekeyword controls context propagation - JSONLD_
PROTECTED - The
@protectedkeyword prevents term redefinition - JSONLD_
REVERSE - The
@reversekeyword specifies reverse properties - JSONLD_
SET - The
@setkeyword specifies an unordered set - JSONLD_
TYPE - The
@typekeyword specifies the type of a node or value - JSONLD_
VALUE - The
@valuekeyword specifies the value of a typed or language-tagged literal - JSONLD_
VERSION - The
@versionkeyword specifies the JSON-LD version - JSONLD_
VOCAB - The
@vocabkeyword sets the default vocabulary for terms - TOON_
BASE - TOON-LD shorthand for
@base - TOON_
CONTAINER - TOON-LD shorthand for
@container - TOON_
DIRECTION - TOON-LD shorthand for
@direction - TOON_
GRAPH - TOON-LD shorthand for
@graph - TOON_ID
- TOON-LD shorthand for
@id - TOON_
IMPORT - TOON-LD shorthand for
@import - TOON_
INCLUDED - TOON-LD shorthand for
@included - TOON_
INDEX - TOON-LD shorthand for
@index - TOON_
JSON - TOON-LD shorthand for
@json - TOON_
LANGUAGE - TOON-LD shorthand for
@language - TOON_
LIST - TOON-LD shorthand for
@list - TOON_
NEST - TOON-LD shorthand for
@nest - TOON_
NONE - TOON-LD shorthand for
@none - TOON_
PREFIX - TOON-LD shorthand for
@prefix - TOON_
PROPAGATE - TOON-LD shorthand for
@propagate - TOON_
PROTECTED - TOON-LD shorthand for
@protected - TOON_
REVERSE - TOON-LD shorthand for
@reverse - TOON_
SET - TOON-LD shorthand for
@set - TOON_
TYPE - TOON-LD shorthand for
@type - TOON_
VALUE - TOON-LD shorthand for
@value - TOON_
VERSION - TOON-LD shorthand for
@version - TOON_
VOCAB - TOON-LD shorthand for
@vocab
Functions§
- decode
- Decode TOON-LD string to JSON-LD format
- encode
- Encode JSON-LD string to TOON-LD format
- get_
toon_ keyword - Returns the TOON-LD display key for a JSON-LD keyword.
- is_
keyword - Checks if a string is a JSON-LD keyword (starts with @)
- keyword_
order - Returns the serialization order priority for a JSON-LD keyword.
Type Aliases§
- Result
- Result type for TOON-LD operations