Crate toon_ld

Crate toon_ld 

Source
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§

JsonLdContext
JSON-LD context for prefix expansion/compaction.
ToonParser
TOON-LD Parser
ToonSerializer
TOON-LD Serializer

Enums§

ToonError
Errors that can occur during TOON-LD operations
Value
Represents any valid JSON value.

Constants§

JSONLD_BASE
The @base keyword sets the base IRI for relative IRIs
JSONLD_CONTAINER
The @container keyword specifies how values are organized
JSONLD_CONTEXT
The @context keyword defines the vocabulary mapping for terms
JSONLD_DIRECTION
The @direction keyword specifies text direction (ltr/rtl)
JSONLD_GRAPH
The @graph keyword contains a named graph
JSONLD_ID
The @id keyword identifies a node with an IRI
JSONLD_IMPORT
The @import keyword imports an external context
JSONLD_INCLUDED
The @included keyword specifies included nodes
JSONLD_INDEX
The @index keyword specifies an index value for a node
JSONLD_JSON
The @json keyword marks a JSON literal value
JSONLD_LANGUAGE
The @language keyword specifies the language of a string value
JSONLD_LIST
The @list keyword specifies an ordered list
JSONLD_NEST
The @nest keyword specifies nested properties
JSONLD_NONE
The @none keyword represents the default index value
JSONLD_PREFIX
The @prefix keyword indicates a term is a prefix
JSONLD_PROPAGATE
The @propagate keyword controls context propagation
JSONLD_PROTECTED
The @protected keyword prevents term redefinition
JSONLD_REVERSE
The @reverse keyword specifies reverse properties
JSONLD_SET
The @set keyword specifies an unordered set
JSONLD_TYPE
The @type keyword specifies the type of a node or value
JSONLD_VALUE
The @value keyword specifies the value of a typed or language-tagged literal
JSONLD_VERSION
The @version keyword specifies the JSON-LD version
JSONLD_VOCAB
The @vocab keyword 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