Skip to the content
GigaJSON
All tools
Format and check
View and query
Convert
JSON to code
Encode and decode
Sample files
Guides Open GigaJSON

How to reduce JSON tokens for AI prompts

· 5 min read · By Amir Badi

An API response usually carries far more than your AI prompt needs. Ask about four devices and you might get inventory metadata, agent versions, timestamps and the same field names repeated dozens of times. Before you paste the whole thing, look at what you're about to send.

GigaJSON's JSON Token Counter counts the tokens in your input, compares compact JSON with TOON, and lets you pick which fields or rows to keep. The JSON to TOON converter does a straight conversion when you want everything. Both run in your browser, cost nothing, and need no account or AI API key.

Below is a worked example, plus a case where compact JSON comes out smaller.

Start with the question you want answered

GigaJSON grew out of work with large device and usage exports from services such as Jamf and Intune. Here we use a small synthetic inventory instead of real machine data.

Say you want to know: Which devices are marked non-compliant, and what platform does each use? The example has four device records with these fields:

  • id, platform and compliant
  • department, lastSeen and agentVersion

A metadata object describes the export. For this question you need only the first three fields. Ask about outdated agents and you'd keep agentVersion as well. Pick the data for the task first, then worry about making the text smaller.

To follow along, click Example in either tool, or open the sample device inventory. We kept it small so you can check it by eye.

Compare compact JSON and TOON with all data included

Leave all the data selected first. We measured the built-in example with the same code the tools use:

Representation Tokens Data included
Original JSON, indented with two spaces 270 All fields, all four devices and metadata
Compact JSON 171 All fields, all four devices and metadata
TOON 127 All fields, all four devices and metadata

Compact JSON drops the formatting whitespace. TOON goes further and changes how the structure is written. Here TOON uses 44 fewer tokens than compact JSON, 25.7% less. Both rows hold identical data, so that saving comes from the format alone.

GigaJSON JSON to TOON converter showing 270 original tokens and 127 TOON tokens for a four-device inventoryGigaJSON JSON to TOON converter showing 270 original tokens and 127 TOON tokens for a four-device inventory (dark theme)
The complete inventory uses 270 tokens as formatted JSON and 127 as TOON, with all original data included. Screenshots follow the page theme. Click to view full size.

TOON stands for Token-Oriented Object Notation. For an array of similar records it writes the field names once, then one row of values per record. The official format documentation explains the structure and when another format suits better.

The converted example begins:

devices[4]{id,platform,compliant,department,lastSeen,agentVersion}:
  mac-001,macOS,true,Engineering,2026-10-10,3.2.1
  win-002,Windows,false,Finance,2026-10-09,3.1.0
  mac-003,macOS,true,Design,2026-10-10,3.2.1
  win-004,Windows,true,Engineering,2026-10-08,3.2.1
metadata:
  source: Example device inventory
  total: 4

Before it shows you a result, the converter decodes its own TOON output and checks it against the parsed input. If the next step needs valid JSON, use compact JSON: a JSON parser can't read TOON.

Keep only the fields your prompt needs

In the JSON Token Counter:

  1. Load the example and open Select data.
  2. Under Data to include, choose devices.
  3. Open Keep fields and keep id, platform and compliant.
  4. Leave First rows empty to keep all four devices.
  5. Compare Compact JSON and TOON, then review the output.

The selected data uses 64 tokens in compact JSON and 44 tokens in TOON. The TOON output is:

[4]{id,platform,compliant}:
  mac-001,macOS,true
  win-002,Windows,false
  mac-003,macOS,true
  win-004,Windows,true
GigaJSON JSON Token Counter with three device fields selected, a 44-token TOON output and a partial-data noticeGigaJSON JSON Token Counter with three device fields selected, a 44-token TOON output and a partial-data notice (dark theme)
Keeping id, platform and compliant produces 44 TOON tokens. The partial-data notice makes the omitted section and fields explicit. Screenshots follow the page theme. Click to view full size.

This output leaves data out. The export metadata, departments, timestamps and agent versions are gone. The tool labels it partial data and leaves your input untouched. Part of the drop from 270 to 44 tokens comes from those missing fields, so don't read it as lossless compression.

The row control keeps the first rows. It won't find all matching records or take a fair sample. To get every non-compliant device in a big inventory, filter on that condition first; the first ten devices might not include the ones you need.

A smaller example where compact JSON wins

Now try this small JSON example:

{
  "a": 1,
  "b": [
    1,
    2,
    3
  ],
  "c": {
    "d": true
  }
}
Representation Tokens
Original formatted JSON 41
Compact JSON 19
TOON 22

All three hold the same values, and compact JSON wins by three tokens. A format that shrinks a repeated inventory may grow another document, so measure your own input before you choose.

Add context around the data

Add a short instruction that explains the task and the fields. For the four-device output above, you could write:

The data below is a device inventory in TOON format.
The header lists the fields; each following row is one device.

List the id and platform of devices where compliant is false.
Use only these records. Do not infer why a device is non-compliant.
This extract includes all four devices, but omits other fields.

[Paste the prepared output here]

GigaJSON doesn't generate that answer; this is only a prompt template. Check whatever the model says against the source records. A smaller input won't make the answer right, and models may read some formats better than others.

What the counts and limits mean

We measured these on 13 October 2026 with gpt-tokenizer 4.0.0 (o200k_base) and @toon-format/toon 4.4.0. The counts cover the exact data text with no trailing newline, and the downloadable examples keep that text as is. The tokenizer project lists the encodings it supports.

The counts leave out the rest of the prompt, the conversation history, tool definitions and the response. Other tokenizers will count differently. Use the numbers to compare formats, and don't treat them as a billing quote. We didn't call an AI model or test answer quality for these examples.

Both tools take JSON up to 2 MiB and 64 nesting levels. The main editor's large-file limits for tree and table are separate. For a large export, open it in the editor and pull out the part you need first; the query guide shows ways to select records. Each query engine has its own size limit, too.

The tools reject duplicate keys, and numbers that parsing would round. Fix those in the source data before you build the prompt. Cutting tokens won't strip secrets for you, so look over the fields and values you plan to share. Your file stays on your machine while you prepare it. Once you paste the output into an AI service, that service has the data.

Try it with your own JSON

Open the JSON Token Counter to compare formats and pick what to keep. For a conversion that keeps every value, use JSON to TOON. Start from one real question, keep the data that answers it, and read the result before it goes into your prompt.

Questions

How can I reduce the tokens in JSON before using it in an AI prompt?

Count the input, compare compact JSON with TOON, and keep only the section and fields your question needs. Compacting and converting change the format; dropping fields or rows removes data. Read the output before you copy it.

Does TOON always use fewer tokens than JSON?

No. Arrays of records with the same fields gain from TOON's shared field names, but other structures can come out smaller as compact JSON. Compare both with the tokenizer your workflow uses.

Does GigaJSON send my JSON to an AI model?

No. Token counting, data selection and TOON conversion happen in your browser without AI calls. If you later paste the output into an AI service, that service receives the data you paste.

Can the token counter prepare a 1 GB JSON file?

The token counter and JSON to TOON converter accept up to 2 MiB each. The main editor's larger tree and table limits are separate. For a larger source, extract the relevant data locally first, then open that smaller result in the token counter.

More from the blog