What the JSON cleaner removes
API responses, form submissions and exported records are often padded with fields that carry no data: null placeholders, empty strings, empty lists and empty objects. This JSON cleaner walks the whole document and drops those values at every level of nesting, so what remains is the data that actually says something.
Example
{
"id": 42,
"title": " Q3 report ",
"note": " ",
"author": null,
"tags": [],
"stats": {"shares": null, "comments": []},
"items": [null, "", 0, false]
}
With the default options the result is below, and the status bar reads "Removed 8 empty values":
{
"id": 42,
"title": " Q3 report ",
"items": [
0,
false
]
}
How cleaning works, level by level
The cleaner works from the inside out. Children are cleaned first, and only then is the parent checked. In the example, stats loses shares and comments, is left as {}, and is then removed as an empty object too. That is why eight values were counted: seven empty fields plus the stats object that became empty.
The same cascade applies to arrays. Empty entries are removed from lists, so [null, "", 0, false] shrinks to [0, false]. The top-level value itself is never removed; a document that is entirely empty comes back as {} or [].
Options
- Remove null – drops keys and array entries whose value is
null. - Remove empty strings – drops
""and also strings that contain only spaces, tabs or line breaks, like" "above. - Remove empty arrays – drops
[], including arrays that become empty after cleaning. - Remove empty objects – drops
{}, including objects emptied by cleaning. Turn it off to keep the structure, for example{"a":{"b":{"c":null}}}then becomes{"a":{"b":{}}}. - Trim whitespace in strings – off by default; removes leading and trailing whitespace from the strings that remain, so
" Q3 report "becomes"Q3 report". Spaces inside a value are kept. - Indent – 2, 3 or 4 spaces or a tab for the output.
The first four options are on by default. Values such as 0, false and "0" are real data and are never removed.
Typical uses
- Shrinking a stored document or a fixture before committing it, when empty fields add noise but no meaning.
- Reading a verbose API response, where dozens of null fields hide the handful that are set.
- Preparing records for a JSON to CSV export, so that empty nested objects do not turn into empty columns.
When not to clean
An empty value is not always meaningless. In a JSON Merge Patch request (the PATCH format of RFC 7396), "field": null means "delete this field", so removing it silently changes the request. Some APIs also distinguish between a missing key and an empty list, for example "no tags" versus "tags not loaded". Clean data you are going to read, archive or compare; think twice before cleaning data you are about to send back to the same API.
Related tools
Cleaning pairs well with a JSON diff when two payloads differ only in empty fields, and with the JSON minifier when the goal is a smaller payload. If the input does not parse, run it through the JSON fixer first.
All cleaning happens in your browser; the JSON is not uploaded unless you use Load URL or Save & Share.