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
How to Query a Large CSV File Without Excel
Open, filter, dedupe, sort, and summarize large CSV or TSV files in the browser without Excel. Learn a practical workflow for big exports and safer manual execution.
How to Write Regex for Log Files
Create practical regex patterns for logs. Learn how to match timestamps, levels, request IDs, IP addresses, URLs, status codes, and error messages from text samples.
CSV Operations Query Tool Online: Filter, Dedupe, Compare CSV and Excel
Use Spoold's free CSV Operations tool to query CSV, TSV, and Excel .xlsx files online. Filter rows, select columns, find unique values and duplicates, dedupe CSV data, compare columns, count by category, sort rows, and run numeric summaries in your browser.