Back to Blog
8 min read
Data

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.

By Spoold Editorial TeamReviewed for tool accuracy
Editorial Policy

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

1

Format the JSON first

Open the JSON Formatter, paste the payload, and validate that it parses before removing fields.
2

Pick what counts as empty

Decide whether you only want to remove null or also "", [], and {}.
3

Keep meaningful falsy values

Never treat false, 0, or "0" as empty unless your business rule explicitly says so.
4

Validate or diff after cleanup

Use JSON Schema Validator or JSON Diff to confirm that the cleaned payload still has the fields your app expects.

JSON cleanup examples

TaskInputResult
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

Removing 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

An empty string can mean missing data, but it can also mean a user intentionally cleared a text field. For writes, compare the API behavior for omitted fields versus "".

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

Recursive cleanup can remove nested empty objects and arrays. That is helpful for display, but it changes the shape of deeply nested payloads.

JSON cleanup checklist

  • 1Validate the JSON before cleaning so syntax errors are not confused with cleanup behavior.
  • 2Decide whether the cleanup should remove only null or 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

Remove empty fields for reading and sharing. Be more careful when cleaning payloads that will be sent back to an API.

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 false because it is a falsy JavaScript value.
  • Treating 0 as 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 null is a delete signal.

FAQ

Should empty arrays be removed from JSON?

Only when they are noise. Empty arrays often mean a list is present but currently has no items, so keep them if that meaning matters.

Is removing null fields the same as minifying JSON?

No. Minifying removes whitespace. Cleaning removes properties and changes the data shape.

Can I remove empty fields before comparing JSON?

Yes, that is one of the best use cases. It reduces noisy diffs from placeholder fields.

Try it in JSON Formatter

Paste a real sample, run the workflow, and use the guide above as a checklist while you inspect the output.

Try It Now

Put this guide into practice with our free tools. No sign-up required.

Open JSON Formatter
How to Remove Null and Empty Fields from JSON | Blog | Spoold