Package com.cedarsoftware.io
Class ToonWriter
java.lang.Object
com.cedarsoftware.io.ToonWriter
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Output a Java object graph in TOON (Token-Oriented Object Notation) format.
TOON is a compact, human-readable format optimized for LLM token efficiency, using approximately 40-50% fewer tokens than equivalent JSON.
Key TOON characteristics:
- Indentation-based structure (no braces/brackets)
- Tabular arrays with CSV-like rows:
items[2]{id,name}: 1,Alice 2,Bob - Minimal quoting (only when necessary)
- Key: value syntax for objects
Example TOON output:
name: John age: 30 address: city: NYC zip: 10001 tags[3]: java,json,toon
- Author:
- John DeRegnaucourt (jdereg@gmail.com)
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Constructor Summary
ConstructorsConstructorDescriptionToonWriter(OutputStream out, WriteOptions writeOptions) Create a ToonWriter that writes to an OutputStream. -
Method Summary
-
Constructor Details
-
ToonWriter
Create a ToonWriter that writes to an OutputStream.- Parameters:
out- OutputStream to write TOON content towriteOptions- configuration options (may be null for defaults)
-
-
Method Details
-
write
Write the given object as TOON format.- Parameters:
obj- the object to serialize- Throws:
JsonIoException- if an error occurs during serialization
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-