Skip to content
LocalOnly

Remove Empty Values from JSON

Stable

Remove empty strings, arrays, objects, and nulls throughout JSON.

Everything is processed locally in your browser

About Remove Empty Values from JSON

The Remove Empty Values tool prunes anything that carries no data from your JSON: empty strings, empty arrays, empty objects, and optionally null. It works recursively and repeatedly, so containers that become empty after their contents are cleaned are removed too. The result is a compact document that keeps only meaningful values.

Features

  • Removes empty strings, empty arrays, and empty objects recursively
  • Optionally treats null as empty and removes it too
  • Re-runs until nested containers that became empty are also pruned
  • Configurable rules so you can keep, for example, empty arrays
  • Preserves meaningful falsy values like 0 and false
  • Reports the number of values removed

How to use Remove Empty Values from JSON

  1. 1

    Paste your JSON

    Add the document with empty fields you want to strip out.

  2. 2

    Select what counts as empty

    Decide whether empty strings, arrays, objects, and null should each be removed.

  3. 3

    Clean

    The tool prunes empty values recursively, including containers emptied by the process.

  4. 4

    Copy the compact JSON

    Use the trimmed result in requests, storage, or comparisons.

Examples

Pruning empty strings, arrays, and objects

Input

{
  "name": "Kit",
  "notes": "",
  "tags": [],
  "meta": {},
  "score": 0
}

Output

{
  "name": "Kit",
  "score": 0
}

How removing empty values from JSON works

"Empty" is a judgement call, and the definition matters

There is no specification for what makes a JSON value empty, so every tool picks a rule. This one treats five things as empty: `null`, the empty string `""`, the empty array `[]`, the empty object `{}`, and containers that become empty once their own empty contents are removed. That last clause is what makes the operation recursive rather than a single pass.

Deliberately excluded are values that are falsy in JavaScript but carry real information. `0` is a number and usually a meaningful one - a count of zero, a price of zero, a temperature of zero. `false` is a definite answer, not a missing one. A string of one space is not the empty string. Treating any of these as empty is a classic source of data loss, because `if (!value)` in JavaScript is true for all of them.

That distinction is the main reason to prefer a tool with an explicit rule over a hand-written filter. Most quick filters written under time pressure use a falsy check and quietly delete every zero in the document.

Why removal has to cascade

Consider `{"user": {"profile": {"bio": ""}}}`. Removing the empty string leaves `{"user": {"profile": {}}}`, which now contains an empty object that was not empty before the operation started. Remove that and `user` becomes empty too.

So the process repeats from the leaves upward until nothing further changes, which in this example reduces the whole document to `{}`. That result is correct but can be startling, and it is worth knowing in advance: a document whose every leaf is empty collapses entirely.

This cascading behaviour is the substantive difference between this tool and the JSON Remove Nulls tool, which removes a single value type in one pass and leaves emptied containers standing.

Where this is genuinely useful

Form submissions are the strongest case. An HTML form sends every input it contains, so untouched text fields arrive as empty strings. Storing those is worse than storing nothing, because later code cannot distinguish "the user cleared this" from "the user never filled it in". Stripping them before persisting keeps records honest.

Scraped and imported data is the second case, where missing cells arrive as empty strings and optional structures as empty containers. The third is cleaning documents before a diff, since a document full of empty placeholders produces a diff full of noise.

The case where you should not use it is any API contract that treats empty as distinct from absent - and for PATCH requests specifically, stripping nulls will break field deletion.

Reference

What is treated as empty

Values that are falsy in JavaScript but meaningful in data are deliberately kept.

ValueRemoved?Reasoning
nullYesNo value present
""YesZero-length string
[]YesNo elements
{}YesNo keys
{"a":{}}Yes, cascadingBecomes empty once its contents go
0NoA number, and usually a meaningful one
falseNoA definite answer, not a missing one
" "NoA space is a character; the string is not empty
"null"NoThe four-character string, not the null value
[null]Becomes []The null goes, then the empty array does too

Which tool should you use?

These tasks overlap. Here is how to pick the right one for what you are actually doing.

You are cleaning a form submission before saving it
This is the ideal case. Empty strings from untouched inputs should not be persisted.
You only want `null` removed and nothing else
The JSON Remove Nulls tool is narrower and does not cascade into containers.
You need zeros and false values preserved
This tool already preserves them. Be careful with hand-rolled falsy filters, which do not.
You are preparing a PATCH request
Do not use either cleanup tool. Nulls are delete instructions in JSON Merge Patch and must survive.

Use cases

  • Cleaning form submissions where blank fields serialize as empty strings
  • Removing empty arrays and objects left over from partial data
  • Compacting API payloads to send only fields that hold data
  • Tidying config files before committing them
  • Normalizing documents before diffing or merging

Troubleshooting common errors

The whole document collapsed to {}

Why: Every leaf value was empty, so the cascade removed each container in turn from the leaves upward.

Fix: Working as intended. If you need the skeleton kept, use the JSON Remove Nulls tool instead, which leaves containers standing.

Zeros were kept and you expected them gone

Why: `0` is a meaningful number and is excluded by design, precisely because falsy checks delete it by accident.

Fix: If you genuinely want zeros removed, do it explicitly in code where the intent is visible to the next reader.

A field the API requires has disappeared

Why: It was empty, and the operation makes no distinction between optional and required fields.

Fix: Re-add required fields after cleaning, or validate against a JSON Schema before sending to catch this automatically.

Strings containing only whitespace survived

Why: Only the zero-length string counts as empty; a space is a character.

Fix: Trim the values upstream if whitespace-only should count as empty.

Limitations

What this tool deliberately does not do, so you know when to reach for something else.

  • `0` and `false` are always preserved, because both carry information.
  • Whitespace-only strings are not treated as empty - no trimming is applied.
  • Removal cascades upward, so a document of entirely empty leaves reduces to `{}`.
  • Required fields are removed just like optional ones; nothing here knows your schema.
  • The operation is not reversible.

Frequently asked questions

Learn more

Command Palette

Search for a tool or command