JSON and Table Compactor for Prompts
Operator: Abdulla Al Fahad. How tools are built and checked
An API response pasted into a prompt spends much of its length on syntax: every record repeats every key in quotes, and pretty-printing adds indentation on every line. When the data is a list of records with the same fields, writing the field names once as a header row carries the same facts in far fewer characters. This tool takes JSON or CSV and builds several compact versions side by side, so you can see which one is cheapest for your data before you paste it.
For JSON you get minified JSON, a header-once table as CSV, TSV and a Markdown table, a YAML-style indented version and a key-value outline with one line per value. For CSV you get TSV, a Markdown table and a minified JSON array. Every version shows its character count, an estimated token count and the change against what you pasted, with a preview, a copy button, a download button and a sentence you can put in the prompt so the model knows what format it is reading.
Key features
- Six forms for JSON: minified, CSV, TSV, Markdown table, YAML style and a path outline
- Three forms for CSV: TSV, Markdown table and a minified JSON array
- Characters, estimated tokens and the change against your input for each form, in one comparison table
- Numbers keep the exact digits they were written with, including long IDs and trailing zeros
- Table forms from an array of objects, or from the one array inside a wrapper object
- Notes when objects have different keys, when nulls become empty cells and when nested values are kept as JSON
- JSON errors reported with line, column and a plain explanation, such as a trailing comma or single quotes
- Copy and download for every form, with a suggested sentence for the prompt
Why numbers stay exact, and the table forms
Input is pasted text, or a .json or .csv file no bigger than 5 MB. A picked file is treated as UTF-8 unless it begins with a UTF-16 byte-order mark. If its bytes turn out not to be valid UTF-8, the page falls back to Windows-1252, the encoding older Excel versions often used for CSV, and shows a line saying so. The input type is detected from the first character (JSON starts with { or [), and a menu lets you force JSON or CSV.
JSON is read by a parser written for this tool rather than the browser's JSON.parse. The difference matters for numbers: JSON.parse turns 12345678901234567890 into 12345678901234567000 and 3.50 into 3.5, while this parser keeps the digits exactly as written in every form. It also keeps a key that appears twice in one object, so the minified JSON still contains both. Nesting deeper than 500 levels is refused rather than risking the page.
Table forms are built when the JSON is an array whose items are all objects, or an object with exactly one such array inside it, the usual shape of a paged API response. The columns are every key found, in the order keys first appear. A missing key and a null both give an empty cell, and a nested object or array is written as minified JSON inside its cell. CSV adds quotes only around values containing commas, quote marks or line breaks; TSV writes a tab inside a value as \t and a line break as \n; the Markdown table escapes pipes as \| and writes line breaks as <br>.
How it works
Typing or pasting starts a short timer; when it runs out, every form is rebuilt from the current text, and a newer edit cancels the pending rebuild, so the forms always match what is in the box. A picked file is checked first: a ZIP or Office file (it starts with PK), a PDF, or anything whose opening 8 KB contains a zero byte is turned away with a message, and a file over 5 MB is refused before it is read in full.
The YAML-style form follows YAML's block layout: two spaces per level, "- " before each list item and "key: value" pairs. A string is left unquoted unless that would change its meaning, so "007", "true", an empty string, text that starts with a dash or holds ": " all get double quotes. The outline writes one line per value, with a path made of .key for object keys and [n] for list positions, such as [2].tags[0]: box; keys with spaces or other symbols are written as ["first name"].
For CSV input, the delimiter is whichever of comma, semicolon or tab appears most often on the first line outside quotes. The first row is the header. Rows longer than the header get columns named Column 5, Column 6 and so on; shorter rows get empty cells. In the JSON array a blank header becomes its position name and a repeated one becomes "Name (2)", because object keys must be unique.
Each form's estimate is worked out the same way: characters and words are counted, the two figures are averaged, and a range is drawn around the midpoint. The saving column compares the middle estimates. The page holds the text in the box and the latest set of forms in memory; each rebuild replaces the previous forms, and Clear empties the box and drops the forms.
Common use cases
- Fitting a long list of API records into a model's context window by switching from pretty JSON to a header-once table
- Pasting a product feed into a prompt as a Markdown table that a person can also read
- Turning a CSV export into a JSON array for a prompt that asks the model to return JSON in the same shape
- Checking whether minifying is enough, or whether a table form is worth the loss of types
- Giving a model one value per line, with its full path, when the question is about specific nested fields
How to use this tool
- Paste JSON or CSV into the box, choose a .json or .csv file, or press Use sample JSON for a small order list with a wrapper object.
- Leave the input type on Detect, or set it to JSON or CSV if the guess is wrong.
- Read the comparison table: the form with the biggest saving is not always the one to use, so check the notes about lost detail.
- Look at the preview of the form you prefer, then press its Copy or Download button.
- Paste the form into your prompt together with its suggested sentence, so the model knows how to read it.
Example
Three stock records as pretty-printed JSON (217 characters, an estimated 48 tokens)
[
{ "sku": "BX-12", "qty": 140, "price": 3.50, "tags": ["box"] },
{ "sku": "BX-24", "qty": 62, "price": 6.10, "tags": ["box", "large"] },
{ "sku": "LBL-A4", "qty": 1200, "price": 0.0825, "discontinued": true }
]CSV (header once): 121 characters, about 31 tokens, 35% fewer than the input
sku,qty,price,tags,discontinued
BX-12,140,3.50,"[""box""]",
BX-24,62,6.10,"[""box"",""large""]",
LBL-A4,1200,0.0825,,true
Other forms of the same input:
TSV 111 characters about 30 tokens -37%
Markdown table 191 characters about 40 tokens -17%
Minified JSON 179 characters about 43 tokens -10%
YAML style 185 characters about 44 tokens -8%
Outline 210 characters about 58 tokens +21%Tips for best results
- On records that share their keys, TSV is usually the smallest form, since a tab is a single character and values are rarely quoted.
- Minified JSON is the safe choice when the model must return JSON or when types matter; it keeps every key and value as they were.
- The outline is often the largest form on lists, as the example shows, but it suits deeply nested data where a question is about one path.
- If the notes say most objects lack most keys, the table is mostly empty cells; the YAML-style form may then be smaller and clearer.
- Cut the data before compacting it. Sending 50 records instead of 5,000 saves far more than any format.
Common pitfalls
Table forms lose the difference between numbers and strings: 7 and "7" both become 7. If the difference matters, say which columns are numbers in the prompt or use minified JSON.
A missing key and a null look the same in a table, both as an empty cell. The notes say when this happened.
Nested values stay as JSON inside table cells, quoted and with doubled quotes in CSV, which is legal but harder to read than a flat column.
In the YAML-style form, quoting is decided for readability; the output follows YAML's block style but is not checked against a YAML parser.
TSV writes tabs and line breaks inside values as \t and \n but does not escape backslashes, so a value that already contains the two characters \n reads the same as a line break.
The token estimate counts characters and words. Real tokenizers often give JSON punctuation its own tokens, so the actual saving from dropping quotes and braces can be larger or smaller than shown; for an exact figure use the counter your model provider offers.
Common errors and how to fix them
- "Remove the comma before ]: JSON does not allow a trailing comma."
- JavaScript and many config files accept a comma after the last item, JSON does not. Delete the comma at the line and column shown.
- The error message mentions JSON Lines (one object per line).
- The box contains several JSON values one after another, which is what a .jsonl export looks like. Wrap the lines in [ and ] and put a comma at the end of each line except the last.
- "Strings in JSON need double quotes, not single quotes."
- The data was written as a Python or JavaScript literal. Replace the single quotes with double quotes, or print it with a JSON serializer in the program that made it.
- A table form is missing and the notes say the objects use too many different keys.
- Above 500 distinct keys, or a table of more than 2,000,000 cells, the table forms are skipped because the grid would be mostly empty. This happens when records are keyed by IDs; reshape them into a list of objects with an id field.
- "This is a ZIP archive or an Office file such as .xlsx, not JSON or CSV text."
- For a spreadsheet, use Excel to Markdown Tables, which is linked under the message; for anything else, export the data as .json or .csv first.
Best practices
- Always paste the suggested sentence with the form, or your own description of the format and what empty cells mean.
- Prefer minified JSON when the answer has to be parsed by a program, and a table when a person and a model both read it.
- Check the preview of long IDs and prices once; they are kept as written, but a source that already rounded them will still be rounded.
- Keep the original file; the compact forms are for prompts, not a replacement for the source data.
Why header-once tables save the most
In a JSON array of records, each record repeats every key with its quotes, a colon and usually a space. With five fields and a thousand records, that is five thousand copies of the field names. A CSV or TSV writes them once, in the header, and each record becomes a single line of values. In the example, the three records go from 217 characters to 121 as CSV, and the gap grows with every record added because the per-record overhead is gone.
Markdown tables save less, because every cell carries a pipe and a space on each side, but they render as a readable table in chat apps and documents, which can be worth the extra characters when people read the prompt too.
When a wrapper object holds the records
Paged APIs often return something like {"page": 1, "orders": [...]}. If exactly one property holds an array of objects, the table forms are built from that array and a note names the properties left out, such as page. The minified JSON, YAML-style and outline forms still contain everything. If two or more properties hold arrays of objects, no table is built, since the tool would have to guess which one you meant; paste the array you want on its own.
Frequently asked questions
Which form should I use?
Pick the smallest form that keeps what the task needs. If the model only reads the data, a header-once table usually wins. If it must return the same structure or the types matter, use minified JSON.
Does minifying change my data?
Only the spacing, plus escapes such as \u00e9, which are written as the character itself. Numbers, key order and repeated keys stay as they were.
Why does the CSV input give a JSON form that is larger?
CSV is already a header-once table, so JSON adds the keys back to every row. That form is there for prompts that need JSON, and every value in it is a string because CSV does not record types.
Can a form with fewer characters still cost more tokens?
It can, and the estimate here will not show it. The figures are built from character and word counts, so they rank the forms mostly by length, while a real tokenizer may split JSON's quotes, braces and commas, or a Markdown table's pipes, into more pieces than their length suggests. Use the saving column to pick which forms to try, then check the one you choose with a token counter for your model, if one is available.
Is my data uploaded?
No. The parser and the converters run inside the open tab, so the text goes nowhere unless you copy or download a form yourself.