Prepare JSON for LLMs — token budget, structured output
Shrink JSON to fit your token budget, normalize messy fields before they confuse the model, and validate structured output that comes back from a completion.
Paste your JSON → Get results instantly (no signup)
→ remove noisy values and remove nulls and empties.
1{2 "name": "Alice",3 "age": 304}Love the result?
Use this exact pipeline in your app, backend, or LLM workflow.
No setup needed. Works with curl, Node, Python.
Uses example data. For edited input, copy from the playground.
Works with:
- GPT, Claude, and Gemini structured output
- Function-calling JSON schemas
- RAG context payloads
- Token-budget-constrained prompts
Example: input → output
Working with LLMs has two JSON problems pointing in opposite directions. On the way in, you have to fit context inside a token budget without losing the signal. On the way out, you have to confirm that the structured output actually matches the schema you asked for in the system prompt. Both directions benefit from the same idea: a cleanup pass that shrinks, normalizes, and stabilizes the payload before it crosses the model boundary.
Going into the model — shrink the prompt
Token budget is the practical constraint for almost every prompt that includes a large input. Long prose blocks help; long JSON blobs full of null, repeated boilerplate, and stringified IDs hurt. A cleanup pass typically reclaims 20–40% of tokens with no loss of meaning:
- drop
nulland empty-string fields that contribute no information - trim leading and trailing whitespace inside string values
- alphabetize keys so two examples in a few-shot prompt look stable rather than randomly ordered
- collapse consecutive duplicate entries in arrays where the model only needs one canonical example
Pair this page with Extract Fields from JSON when the bigger savings come from removing entire keys rather than tightening existing ones.
Coming out of the model — validate structured output
Function-calling and structured-output modes do not always return valid JSON, even with a schema attached to the request. Common failures:
- the model emits
nullfor a field declared non-nullable - a string field comes back with a trailing comma that breaks the parser
- an enum slot returns a near-but-not-exact match (
"PENDING"instead of"pending") - a numeric field arrives as a stringified number
- nested objects come back missing their wrapper key
Run the completion through this page before storing it. Use the same engine as the JSON cleaner — normalize first, then if the consumer is strict, follow up with the JSON Schema Validator for a field-level report.
Use cases tied to model workflows
- RAG context shrinking — strip nulls and trim strings inside a retrieved document before stuffing it into a prompt.
- Structured-output validation — confirm the completion matches the schema you sent in the request.
- Few-shot example normalization — sort keys so example A and example B look identically structured to the model.
- Function-call argument cleanup — sanitize tool-call arguments before executing the tool.
- Eval set deduplication — collapse duplicate or near-duplicate JSON examples in an evaluation dataset.
Token-budget tactics
- Drop nulls aggressively in prompt context. Models do not need to see what isn't there.
- Sort keys deterministically. Same input → same tokens → same KV-cache hits across calls.
- Trim whitespace inside string values. Models tokenize whitespace; trailing spaces cost tokens for nothing.
- Pre-flatten deeply nested structures with Flatten JSON when the prompt asks the model to reason about specific paths — flat keys prompt better.
Pitfalls when prepping JSON for prompts
- Lossy null-strip. If the model is supposed to detect explicit nulls (e.g. "did the user clear this field?"), keep them.
- Order-sensitive prompts. Some prompts depend on a specific array order (event timeline, ranked results). Do not sort arrays in those cases.
- Field renames break few-shot consistency. If your system prompt or few-shot examples reference a key by name, a casing rename quietly breaks them.
Why this is the wedge page for the product
Most JSON tools ignore the LLM workflow entirely. The product vision here is that JSON transformation is increasingly a model-adjacent activity — preparing context, validating completions, debugging tool calls. This page is the entry point for that workflow.
Frequently asked questions
How much token budget can I expect to save?+−
Typically 20–40% on real-world payloads, mostly from null-strip, whitespace trim, and key-sort across few-shot examples. Aggressive shrinking with field extraction (use the Extract Fields tool first) can push that higher.
Does sorting keys actually help model performance?+−
Indirectly — deterministic input means deterministic tokenization, which improves prompt-caching hit rates and makes few-shot examples look uniform to the model. The reasoning isn't proven to help; the cost reduction is real.
Can I validate structured output that came back from a model?+−
Yes. Run the completion through the cleanup pass first, then follow up with the JSON Schema Validator if your consumer is strict. Cleanup catches whitespace and null artifacts; schema validation catches missing fields and type mismatches.
Why not just use a regex or a one-liner?+−
A regex can't distinguish a key value from a string value. Cleanup options here apply structurally — `removeNulls` only touches null-typed fields, not strings that happen to spell 'null'. The same idempotent guarantees apply.
Does this work for GPT, Claude, and Gemini structured output?+−
Yes. The cleanup is provider-agnostic — it operates on the JSON output, not the model. Use it as the post-completion sanitization step regardless of which provider you're calling.
Related tools
Read more on the blog
Advanced usage (optional)
Clean Values
v1.0.0Description
Clean Values
Remove nulls, empty strings, empty collections, default values, and duplicates from JSON data. Optionally trim whitespace and sort keys. A comprehensive cleanup utility for normalizing messy data.
Operations
Each cleanup operation can be toggled independently. Enable multiple operations to clean data in a single pass.
Remove null values
Delete object keys that have null values at any depth.
Remove empty strings
Delete object keys that have empty string "" values.
Remove empty collections
Delete empty objects {} and empty arrays [].
Remove default values
Delete falsy defaults — 0 and false. Useful for stripping placeholder values.
Remove duplicates
Remove duplicate items in arrays. Compares both primitive values and full objects (deep equality).
Trim whitespace
Trim leading and trailing whitespace from all string values throughout the document.
Sort object keys
Sort object keys alphabetically at all levels.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
| Apply to | path-picker | [] | Scope operations to specific paths only (empty = apply everywhere) |
| Remove null values | boolean | true | Remove object keys with null values |
| Remove empty strings | boolean | true | Remove object keys with empty string values |
| Trim whitespace | boolean | true | Trim leading/trailing whitespace from strings |
| Remove empty collections | boolean | false | Remove empty objects {} and arrays [] |
| Remove duplicates | boolean | false | Remove duplicate items in arrays |
| Remove default values | boolean | false | Remove falsy defaults (0, false) |
| Sort object keys | boolean | true | Sort object keys alphabetically |
Use Cases
API Response Cleanup
- Strip null fields from API responses before displaying
- Remove internal metadata fields (
__v,_id) with empty values - Trim whitespace from user-submitted form data
Data Normalization
- Deduplicate records imported from multiple sources
- Sort keys for consistent ordering across objects
- Remove placeholder defaults before exporting
Configuration
| Name | Type | Default | Description |
|---|---|---|---|
| Apply to | path-picker | [] | Scope operations to specific paths only (empty = apply everywhere) |
| Remove null values | boolean | true | Remove object keys that have null values |
| Remove empty strings | boolean | true | Remove object keys that have empty string values |
| Trim whitespace | boolean | true | Trim leading and trailing whitespace from all string values |
| Remove empty collections | boolean | false | Remove empty objects {} and empty arrays [] |
| Remove duplicates | boolean | false | Remove duplicate items in arrays (primitives and objects) |
| Remove default values | boolean | false | Remove falsy defaults (0, false) |
| Sort object keys | boolean | true | Sort object keys alphabetically |
Examples
Clean up this JSON and remove noisy values and remove nulls and empties.1{2 "name": "Alice",3 "age": 304}API Usage
curl -X POST https://your-domain.com/api/v1/utilities/cleanup.clean-json \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"inputs":{"primary":{"name":"Alice","bio":"","age":30,"address":null,"tags":[],"meta":{}}},"config":{"removeNulls":true,"removeEmptyStrings":true,"removeEmptyCollections":true,"removeDefaults":false,"removeDuplicates":false,"trimStrings":false,"sortKeys":false}}'1{2 "name": "Alice",3 "age": 304}