How to Remove Null Values from JSON Recursively
Null values sneak into JSON from ORMs, forms, and API serializers, bloating payloads and complicating merges. Here is how to remove them recursively - and when not to.
Open almost any API response or database export and you will find fields sitting there with a value of null - a phone number nobody entered, an address that was never confirmed, a middle name left blank. Each one is technically valid JSON, but multiplied across thousands of records or a deeply nested config, those nulls add noise, inflate payload size, and complicate anything that tries to merge or diff the data.
This guide walks through what it actually means to remove a null value (as opposed to just hiding it), why nulls show up so often in real-world JSON, and how to clean them out safely. You will also see how the Remove Nulls from JSON tool handles the recursion, array positions, and empty-object edge cases automatically, entirely inside your browser.
What does removing nulls from JSON actually mean?
In JSON, null is a real, explicit value - it is not the same as a key being absent. {"nickname": null} and {} describe two different things: the first says "we checked, there is no nickname," the second says "we never asked." Removing nulls means deleting the property entirely wherever its value is null, so the document ends up looking like the key was never set in the first place.
Because JSON documents nest arbitrarily deep, a useful null-removal pass has to walk the whole tree: top-level fields, objects nested inside objects, and objects or primitives sitting inside arrays. A one-level filter would miss the null buried three levels down in a profile.address.suite field, which is exactly where these things tend to hide.
Stripping nested null fields
A user record with nulls at two different depths.
Input
{
"id": 204,
"email": "sam@example.com",
"phone": null,
"profile": {
"bio": "Backend engineer",
"avatarUrl": null,
"location": null
}
}Output
{
"id": 204,
"email": "sam@example.com",
"profile": {
"bio": "Backend engineer"
}
}Why null values pile up in real JSON
Nulls rarely get typed in by hand - they are usually a side effect of how the data was generated. Once you notice the pattern, they show up everywhere:
- ORMs and database drivers that serialize
NULLcolumns directly to JSONnull, even for fields your application never touches. - Form submissions where an optional input was left blank and the frontend sends
nullinstead of omitting the key. - API responses that explicitly set a field to
nullto signal "this exists on the schema but has no value yet." - Data exports and ETL pipelines that flatten sparse records into a uniform shape, padding missing fields with
null. - Templating or code generation tools that always emit every declared property, defaulting unset ones to
null.
Why stripping nulls matters
A handful of nulls in a small object is harmless. The problem shows up at scale: a large export with thousands of records, each carrying a dozen null fields, wastes real bandwidth and storage for information that says nothing. Cleaning them up has a few concrete payoffs:
- Leaner payloads - fewer bytes over the wire and less to parse on the receiving end.
- Correct merge semantics - many merge and patch strategies treat an absent key as "leave it alone" but an explicit
nullas "clear this value." If you are about to run a JSON merge, stray nulls can unintentionally wipe out fields you meant to keep. - Cleaner diffs - a document with fewer incidental nulls produces version-control diffs where the fields that actually carry data stand out.
- Simpler downstream code - consumers that treat "key missing" and "value present but null" the same way no longer need extra null checks.
How the Remove Nulls tool works
Remove Nulls from JSON parses your document, then walks it recursively: for every object, it drops any property whose value is exactly null, and it repeats the same check inside every nested object and array it finds. Only the literal value null is affected - false, 0, and "" are meaningful values in their own right and are left completely untouched.
Arrays get special treatment because removing an element changes every index after it. You can choose to drop null entries from arrays (shrinking the array) or keep them in place so positions and lengths stay exactly as they were - useful when an array represents fixed slots, like a row of monthly totals where a missing month should still occupy its position.
There is also an option to prune objects that end up empty once their nulls are gone. If a profile object contained nothing but null fields, removing them leaves {} behind; pruning takes the next step and removes that now-empty object too, rather than leaving an orphaned, meaningless container in the output.
Nothing you paste ever leaves your browser
Null-heavy exports often carry customer records, tokens, or internal identifiers. Remove Nulls from JSON runs the entire parse-clean-serialize pass on your device - there is no upload, no server logging, and no network request involved, so it is safe to paste production data straight in.
Step-by-step: strip nulls from a JSON document
- Open Remove Nulls from JSON and paste in the document you want cleaned.
- Decide how arrays should be handled - drop null elements to shrink arrays, or keep them to preserve indices.
- Optionally enable pruning of objects that become empty once their null fields are removed.
- Run the cleanup and check the count of removed values to confirm what changed.
- Copy the resulting JSON into your request, config file, or storage layer.
The whole pass happens instantly, even on documents with thousands of nested nulls, because it is just parsing and re-serializing - no server round trip to wait on.
Common use cases
- Trimming null fields out of an API payload before sending it, so only fields with real values are transmitted.
- Cleaning up a database export where every missing column serialized as
null. - Reducing config file noise by omitting settings that were explicitly left null instead of unset.
- Preparing a document for a merge or patch operation where a stray null would otherwise overwrite good data.
- Shrinking a document before hashing or comparing it, so incidental nulls do not affect equality checks.
Common mistakes when removing nulls
Confusing null with other falsy values
null, false, 0, and "" are all distinct, meaningful JSON values. A naive cleanup script that checks for "falsy" values in a language like JavaScript can accidentally delete a count of 0 or a subscribed flag of false along with the actual nulls. A correct null-removal pass checks specifically for the literal null, nothing else.
Breaking array positions without meaning to
If an array represents ordered or indexed data - say, a value per day of the week - silently dropping null entries shifts every element after it into the wrong slot. Decide up front whether the array's positions carry meaning, and if they do, keep nulls in place rather than compacting the array.
Leaving empty objects behind
Removing every null property from an object can leave {} sitting where meaningful data used to be. If that empty shell has no purpose in your schema, prune it as part of the same pass; otherwise you trade one kind of noise for another. If your goal is a fully compact document rather than just null-free, the Remove Empty Values tool goes further and also strips empty strings, arrays, and objects.
Best practices for cleaning nulls
- Decide, per field, whether
nulland "absent" should be treated as equivalent before you strip anything - some APIs distinguish them deliberately. - Keep null elements in arrays that represent fixed, ordered slots; drop them only when the array is a simple, unordered collection.
- Run null removal before a JSON merge if your merge strategy treats explicit nulls as "clear this field."
- Format the cleaned result afterward with a JSON Formatter so the smaller document is still easy to read and review.
- For anything containing customer data, tokens, or credentials, use a tool that processes locally rather than pasting it into a service that uploads your input.
Check the removal count
Before committing a cleaned file, glance at how many nulls were removed. A number far higher or lower than expected is a good early signal that the source data - or your assumptions about it - changed.
Related tools
Remove empty strings, arrays, objects, and nulls throughout JSON.
Pretty-print JSON with configurable indentation and instant validation.
Deep-merge two or more JSON objects into one.
Strip whitespace to shrink JSON to the smallest valid payload.
Related guides
Blank fields, empty arrays, and leftover empty objects bloat JSON payloads and slow down diffs. This guide explains how to prune them safely and recursively, right in your browser.
Minified JSON is unreadable and hard to debug. This guide covers how JSON formatting works, when to use it, common mistakes, and how to pretty-print JSON without uploading it anywhere.
Combining two configs by hand often clobbers nested data you meant to keep. This guide explains how deep merging actually works and how to merge JSON objects safely.
Every extra space and newline in a JSON file costs bytes on the wire. This guide explains how minifying works, when it matters, and how to compress JSON in your browser without uploading it anywhere.