How to Remove Empty Values from JSON (Strings, Arrays, Objects)
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.
Blank form fields, optional attributes nobody filled in, and partial API responses all tend to leave the same trail behind: empty strings, empty arrays, and empty objects scattered through a JSON document. None of it is wrong, exactly - it is just noise that makes payloads bigger and diffs harder to read than they need to be.
This guide walks through what counts as an "empty" value, why cleaning it up matters, and how to do it without accidentally deleting data that only looks empty at a glance. You will also see how Remove Empty Values from JSON handles the recursive cleanup automatically, entirely inside your browser.
What counts as an empty value in JSON?
In this context, "empty" means a value that carries no information: an empty string "", an empty array [], an empty object {}, and - if you choose - null. These are distinct from falsy-but-meaningful values like 0, false, or the number 0.0, which represent real data and should never be treated the same way.
The distinction matters because a naive cleanup script that checks if (!value) in JavaScript will happily wipe out a quantity of 0 or a flag set to false, silently corrupting the data. A correct empty-value cleaner checks the type and shape of each value explicitly rather than relying on truthiness.
Empty vs. meaningful falsy values
Only the truly empty fields disappear; 0 stays intact.
Input
{
"name": "Kit",
"notes": "",
"tags": [],
"meta": {},
"score": 0
}Output
{
"name": "Kit",
"score": 0
}Why pruning empty values matters
A single blank field is harmless. A large document full of them is not - it wastes bandwidth, clutters logs, and makes it harder to see which fields actually hold data. Cleaning empty values up front has a few concrete payoffs:
- Smaller payloads - fewer bytes to send over the wire, especially in high-volume APIs.
- Clearer diffs - version control shows only fields that carry real content, not blank placeholders.
- Easier comparisons - two documents with different sets of blank fields still compare as equivalent once emptiness is stripped.
- Cleaner storage - databases and search indexes do not waste space or relevance scoring on empty strings and containers.
It is especially useful right before you merge two JSON objects, since empty placeholders from one side can otherwise overwrite good data from the other.
How recursive pruning works
A simple pass over the top level of an object is not enough. Consider a "meta": { "tags": [] } field: the outer object is not empty by itself, but once its only child (an empty array) is removed, meta becomes {} - which is now empty too. A thorough cleaner has to walk the document depth-first, remove empty leaves first, and then check whether their parent became empty as a result.
That is exactly what Remove Empty Values from JSON does: it re-runs the pruning pass until no more empty containers remain, so nested structures are cleaned all the way down, not just at the surface. Arrays are walked the same way - empty strings or empty objects inside an array are removed, and if that leaves the array itself empty, the array goes too.
Your JSON never leaves your browser
Pruning is pure local computation - no network round trip is required. The Remove Empty Values from JSON tool runs entirely client-side, so form submissions, customer records, or internal config containing sensitive fields are never uploaded, logged, or stored anywhere.
Step-by-step: strip empty values from your JSON
- Open Remove Empty Values from JSON and paste the document you want to clean into the input panel.
- Choose which categories count as empty for your case: empty strings, empty arrays, empty objects, and optionally
null. - Run the cleanup. The tool recursively removes matching values and prunes any container left empty as a result.
- Check the reported count of removed values, then copy or download the compacted JSON.
Because the rules are configurable, you can decide, for example, to keep empty arrays but still remove empty strings and objects - useful when an empty array is a meaningful "no items yet" state in your schema rather than missing data.
Common use cases
- Cleaning form submissions where every unfilled field serializes as an empty string.
- Removing empty arrays and objects left behind by partial or draft data.
- Compacting API request or response bodies to send only fields that hold data.
- Tidying configuration files before committing them, so reviewers only see meaningful keys.
- Normalizing two documents before comparing or merging them, so blank placeholders do not register as differences.
Common mistakes and how to avoid them
Treating every falsy value as empty
A hand-rolled cleanup that uses a generic truthiness check will strip out 0, false, and even the number 0 used as a valid quantity or score. Always confirm your tool checks type and shape (empty string, empty array, empty object) rather than JavaScript truthiness.
Cleaning in a single pass
Removing empty leaves once can leave newly-empty parent objects or arrays behind. If your cleanup script does not re-check parents after removing their children, you will end up with a document still full of {} and [] husks.
Confusing "empty" with "null"
null and "" mean different things in most schemas: one often signals "explicitly no value," the other "a blank value was provided." If that distinction matters to your data, keep the null-handling option separate rather than always bundling it in with other empty types. If you specifically need to strip only null values, Remove Nulls from JSON is the more precise tool for that job.
Best practices for pruning empty values
- Decide upfront whether empty arrays represent "no data" or a meaningful empty state before pruning them away.
- Run pruning before diffing, merging, or storing documents so blank fields never masquerade as real differences.
- Keep null handling as a separate, deliberate choice rather than lumping it in by default.
- Format the cleaned result with a JSON formatter afterward so the trimmed document stays easy to read.
- For sensitive payloads, use a tool that runs locally in the browser rather than one that uploads your data to a server for processing.
Related tools
Recursively strip every null value from a JSON document.
Pretty-print JSON with configurable indentation and instant validation.
Strip whitespace to shrink JSON to the smallest valid payload.
Deep-merge two or more JSON objects into one.
Related guides
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.
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.
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.
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.