JSON Cleaner

Remove null and empty values from JSON.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

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

  1. The JSON is parsed and walked from the deepest values upward.
  2. Each value is checked against the rules you enabled.
  3. Containers whose contents were all removed become empty and are removed in turn, so a nested object full of null disappears 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"}.

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

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.

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.

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.

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.