Overview
Introduction
Sending tabular data to a large language model as JSON means repeating every column name on every single row, which burns tokens fast on anything with more than a handful of rows.
TOON solves that by writing the shared field names once, in a header line, and then just the values on each row after that, the same way a CSV avoids repeating column names on every line, while still keeping enough structure for a model to parse reliably.
What Is CSV to TOON?
A CSV-to-TOON converter that turns CSV rows into TOON's tabular array syntax: a single `rows[N]{field1,field2,...}:` line declaring the row count and field names once, followed by one indented, comma-separated line of values per row.
It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.
How CSV to TOON Works
The input is parsed with this repo's shared delimited-text CSV parser, using the header row as the field names and each subsequent row as a record keyed by those names, honoring quoted fields exactly like a standard CSV parser would.
The row count and field names become the `rows[N]{...}:` header line, and each row's values are written on their own indented line, in the same field order as the header, joined by commas; a value is wrapped in double quotes (doubling any internal quotes) only if it contains a comma, colon, double quote, newline, or leading/trailing whitespace.
When To Use CSV to TOON
Use it when you need to hand tabular data (a CSV export, a spreadsheet extract, a database query result) to a language model and want to spend fewer tokens on it than a JSON array of objects would cost.
It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.
Often used alongside CSV to JSON Converter, CSV to String Converter and String to CSV Converter.
Features
Advantages
- Field names are written once instead of being repeated as a JSON key on every row, meaningfully reducing token count for larger tables.
- Bare (unquoted) values keep the common case compact, only paying the cost of quoting for values that actually need it.
- Reuses this repo's already-tested RFC 4180 CSV parser, so quoted fields, embedded commas, and embedded newlines in the source CSV are handled correctly.
Limitations
- Only implements TOON's tabular-array-of-uniform-objects syntax; it doesn't attempt other TOON constructs like nested objects or non-uniform arrays, since a flat CSV doesn't have that structure to begin with.
- All CSV values are treated as strings; TOON output doesn't distinguish numbers or booleans from text the way a JSON conversion would, since a CSV cell has no inherent type information either.
Examples
Best Practices & Notes
Best Practices
- Run the CSV Delimiter Detector and Normalizer first if your source data isn't already comma-delimited, since this converter expects standard comma-delimited CSV input.
- Double-check column headers for stray whitespace before converting, since they become the field names shared by every row in the TOON output.
- Prefer TOON over JSON specifically when sending sizeable uniform tables to a language model where token cost matters; for small or deeply nested data, plain JSON is often simpler.
Developer Notes
CSV parsing delegates to this repo's shared `parseDelimited` helper (also used by the JSON category's CSV-to-JSON converter) rather than a second hand-rolled parser. The TOON quoting rule is implemented as `value.includes(",") || value.includes(":") || value.includes('"') || value.includes("\n") || value.includes("\r") || value !== value.trim()`, and quoting doubles internal double quotes the same way CSV does.
CSV to TOON Use Cases
- Compressing a CSV export of records before pasting it into a language model prompt to reduce token usage
- Converting a database query result exported as CSV into a more model-friendly format for a RAG or agent pipeline
- Preparing tabular data for any workflow that specifically expects TOON input
Common Mistakes
- Assuming TOON output preserves data types (numbers, booleans); like CSV, every value is just text unless the consuming system parses it further.
- Feeding in a non-comma-delimited file directly; convert it to comma-delimited CSV first (with the CSV Delimiter Detector and Normalizer) so the header/field-name split works correctly.
Tips
- If a downstream tool needs JSON instead, use Convert CSV to JSON on the same input rather than trying to convert TOON output back to JSON by hand.
- Keep header/field names short and consistent, since they're repeated only once but still count toward the token budget you're trying to reduce.