Skip to content

Lucee toon-format ext

License

Notifications You must be signed in to change notification settings

lucee/extension-toon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TOON Extension for Lucee

Serialize and deserialize TOON (Token-Oriented Object Notation) - an LLM-optimized format that uses ~40-50% fewer tokens than JSON.

Uses the json-io library

Installation

Download the .lex file from releases and install via Lucee Admin, or drop it into your server's deploy directory.

Usage

SerializeTOON

result = SerializeTOON( var [, options] )

Arguments:

  • var - CFML data to serialize (struct, array, or any value) (required)
  • options - Optional struct with serialization options:
    • prettyPrint - boolean (default false). Format output for readability

DeserializeTOON

result = DeserializeTOON( source [, options] )

Arguments:

  • source - TOON string content or file path to read from (required)
  • options - Optional struct with deserialization options:
    • charset - string (default UTF-8). Character encoding when reading from file

Examples

Basic Serialization

data = { name: "Zac", age: 42, tags: [ "lucee", "cfml" ] };

// Serialize to TOON
toon = SerializeTOON( data );

// With pretty print
toon = SerializeTOON( data, { prettyPrint: true } );

Basic Deserialization

// From string
toonString = '(name:"Zac" age:42 tags:["lucee" "cfml"])';
data = DeserializeTOON( toonString );

// From file
data = DeserializeTOON( "/path/to/data.toon" );

// With charset option
data = DeserializeTOON( "/path/to/data.toon", { charset: "UTF-16" } );

Why TOON?

TOON is designed for LLM (Large Language Model) communication:

  • 40-50% fewer tokens than JSON
  • No quotes around keys
  • No commas between elements
  • Compact representation

Example comparison:

{"name":"Zac","age":42,"tags":["lucee","cfml"]}
(name:"Zac" age:42 tags:["lucee" "cfml"])

Known Issues

  • Circular references not supported - Data structures with circular references will cause a StackOverflowError. This is due to a bug in json-io's ToonWriter where cycle detection is not applied to Map/Collection types.
  • Currently only for Lucee 7.1.0.21+ due to OSGI tech debt, only fixed in 7.1

Dependencies

Uses json-io (bundled, Apache 2.0 license).

License

Apache License 2.0

About

Lucee toon-format ext

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published