JSON Cleaner
Remove null and empty values from JSON.
JSON Cleaner – Remove Null and Empty Values from JSON
The JSON cleaner strips the noise out of JSON documents: null values, empty strings, empty arrays, and empty objects. The result is smaller, easier to read, and ready to store or send. Every rule is a switch, so you decide exactly what counts as "empty".
Why clean JSON?
Many APIs and ORMs serialize every field of a model, even the ones that have no value. That bloats responses, clutters logs, and makes documents harder to review. Removing empty fields before saving data to a document database, sending it to an analytics service, or committing a fixture file keeps things tidy. Some APIs also treat a field that is present but null differently from a missing field — cleaning lets you send only what you mean.
How the cleaning works
- The JSON is parsed and walked from the deepest values upward.
- Each value is checked against the rules you enabled.
- Containers whose contents were all removed become empty and are removed in turn, so a nested object full of
nulldisappears entirely.
Numbers (including 0) and booleans (including false) are never removed. With Trim strings on, surrounding whitespace is removed from every string first, so values like " " count as empty.
Example
{"name": "Ann", "email": null, "tags": [], "address": {"zip": ""}} becomes {"name": "Ann"}.
Related tools
Sort the cleaned keys with the JSON Sorter, compare before and after with JSON Diff, or shrink the result further with the JSON Minifier.
Frequently Asked Questions
Are 0 and false removed too?
No. Zero and false are meaningful values, so they are always kept. Only null, empty strings, empty arrays, and empty objects are removed, and each of those can be switched off individually.
What happens to an object that only contained empty values?
Cleaning works from the inside out. If all fields of a nested object are removed, the object itself becomes empty and is removed as well (when “Remove empty objects” is on). The same applies to arrays.
Does trimming change the data?
Trim strings removes leading and trailing whitespace from every string value. A string that consists only of spaces becomes empty and is then removed if “Remove empty strings” is on. Leave trimming off if whitespace is significant.
Are array positions preserved?
Removed array items are dropped, so later items move up. If position matters (for example in coordinate pairs), turn off “Remove null” and “Remove empty strings” for that document.