How to Remove Null and Empty Fields from JSON
Clean JSON objects and API payloads by removing null values, empty strings, empty arrays, and empty objects. Learn safe cleanup rules, examples, and when not to strip fields.
Clean noisy JSON without breaking the meaning of the payload
Many API responses include optional fields as null, empty strings, empty arrays, or empty objects. Removing those fields can make JSON easier to read, compare, store, and send to another API. The important part is choosing a cleanup rule that does not delete meaningful values such as false, 0, or an intentionally empty list.
When to use this guide
API response cleanup
Shorten verbose payloads before sharing them in tickets, docs, support notes, or bug reports.
Diff and review prep
Remove empty noise before comparing two JSON objects so the real changes are easier to see.
LLM prompt input
Trim empty properties from examples before sending structured data to a model or prompt template.
Configuration review
Clean generated config files that include many placeholder keys with no actual value.
Safe cleanup workflow
Format the JSON first
Pick what counts as empty
null or also "", [], and {}.Keep meaningful falsy values
false, 0, or "0" as empty unless your business rule explicitly says so.Validate or diff after cleanup
JSON cleanup examples
| Task | Input | Result |
|---|---|---|
| Remove null | {"name":"Ava","phone":null} | {"name":"Ava"} |
| Remove empty string | {"title":"","status":"draft"} | {"status":"draft"} |
| Keep false | {"active":false,"deletedAt":null} | {"active":false} |
| Nested cleanup | {"user":{"email":"","id":42},"tags":[]} | {"user":{"id":42}} |
What should count as an empty JSON value?
The safest JSON cleanup rule depends on how the payload will be used after cleaning. A support screenshot, a diff, and an API write request all have different risk levels.
Remove null for readability
null is usually safe for examples, logs, screenshots, and API response review. It makes optional fields disappear from the visual noise.Treat empty strings carefully
"".Do not delete false or zero
false and 0 are valid values in flags, counts, billing, inventory, and feature settings. They are not empty.Clean recursively only when intended
JSON cleanup checklist
- 1Validate the JSON before cleaning so syntax errors are not confused with cleanup behavior.
- 2Decide whether the cleanup should remove only
nullor also empty strings, arrays, and objects. - 3Keep
false,0, and meaningful empty arrays unless you have a domain rule. - 4Run a before-and-after comparison in JSON Diff before using the cleaned payload in production.
When not to remove empty fields
Empty values can be meaningful in update APIs. A null field may mean "clear this value", while an omitted field may mean "leave it unchanged". Before cleaning a production request body, check the API contract. For display, debugging, and comparison, removing empty fields is usually safe. For write operations, validate the behavior first.
Cleanup rule
Related workflow
This guide is designed to pair with the tool linked below. Use the article to understand the workflow, then open the tool with a real sample so you can validate the result instead of copying a generic answer from a search result.
Common mistakes to avoid
- Deleting
falsebecause it is a falsy JavaScript value. - Treating
0as empty in analytics, billing, or inventory data. - Removing empty arrays when the API uses them to mean "intentionally no items".
- Cleaning a PATCH request without checking whether
nullis a delete signal.
FAQ
Should empty arrays be removed from JSON?
Is removing null fields the same as minifying JSON?
Can I remove empty fields before comparing JSON?
Try it in JSON Formatter
Related Articles
curl Diff Checker Online — Diff Two curl Commands Side by Side
Free curl diff checker online: paste two curl commands and see header, URL, auth, and body differences. Use Spoold curl Compare as your curl diff tool—client-side, no upload.
Compare curl Requests Online — Side-by-Side HTTP Request Diff
Compare curl request online: paste two HTTP curls from DevTools or Postman and diff method, URL, headers, auth, and body. Free Spoold curl Compare—no upload.
Find the curl Difference: Headers, Auth, and Body Side by Side
Find the curl difference between two requests—Authorization, headers, query, and JSON body. Use Spoold curl Compare to spot token drift and payload changes online.