Remove null values from JSON
Runs locallyStrip every null value and null array entry, at every level.
JSON input
Result
null, missing and empty are three different things
Stripping nulls looks like tidying. In several common contexts it changes the meaning of the document rather than its size, because null is not a synonym for absent — it is a value that some protocols and schemas treat as significant. To also drop empty strings, arrays and objects, use Remove Empty Values.
Before removing them, it is worth knowing which of the three states your consumer actually distinguishes.
A PATCH body
{
"name": "shop-api",
"description": null,
"replicas": 3
}Two very different requests
With null kept (RFC 7386 merge patch): set name, DELETE description, set replicas With null stripped: set name, LEAVE description exactly as it was, set replicas
Same tidy-looking edit, opposite outcome for one field. This is the case where removing nulls is a bug rather than a clean-up.
Where people get caught
In a JSON Merge Patch, null means delete
RFC 7386 defines null as the instruction to remove a member. Strip nulls from a PATCH body and every intended deletion silently becomes "leave unchanged" — the request still succeeds, which is what makes it hard to spot.
JSON Schema treats null and absent separately
{"type": "string"} rejects null, while required only checks whether the key exists. A document that validated with the key absent can fail once you add it back as null, and vice versa.
Removing nulls from an array changes its length
Objects lose a key; arrays lose a position. If anything downstream indexes by position — a CSV column, a fixed-order tuple — compacting the array shifts every value after the hole.
"Empty" is a much bigger hammer than "null"
Null, "", [] and {} are four distinct values. Removing all of them turns "the user cleared this field" into "the user never touched it", which matters in forms and audit trails.
Some stores index the difference
Databases and document stores frequently distinguish a missing attribute from a null one for queries and indexes. A record cleaned of its nulls can stop matching a filter that a record with explicit nulls matched.
About removing null values
How it works in 4 steps · 4 common use cases · 3 questions answered
About removing null values
How it works in 4 steps · 4 common use cases · 3 questions answered
How it works
- 1.Paste the JSON document you want cleaned.
- 2.Every key whose value is null is dropped, at any nesting depth.
- 3.Null entries inside arrays are removed too, and the remaining elements close up.
- 4.Copy the cleaned document.
Common use cases
- •Trimming a response down to the fields that actually carry data before reading it
- •Preparing a PATCH body for an API that treats an explicit null as delete this field
- •Shrinking a fixture where most optional fields came back empty
- •Cleaning a payload produced by an ORM that serialises every unset column
FAQ
Is there a difference between a missing key and a key set to null?
Often yes, and it matters. Many APIs read an explicit null as clear this value and a missing key as leave it alone. Strip nulls only when you mean the second.
Are empty strings and empty arrays removed too?
No — this tool touches nulls only. Use Remove Empty Values for the more aggressive clean that also drops "", [] and {}.
Does removing nulls from an array shift the indexes?
Yes. The remaining elements close up, so anything referring to a position by index needs rechecking afterwards.