โ† Back to blog
Cleanup

Clean API Responses: Remove Nulls, Trim Whitespace, Normalize JSON

Learn how to clean messy API responses by removing nulls, trimming whitespace, and normalizing JSON for storage, comparison, and downstream APIs.

2026-02-253 min readUpdated Apr 29, 2026
Before and after cleaning messy API JSON data

API responses can be valid JSON and still be full of noise that makes downstream systems fragile.

Third-party payloads often include null values, empty strings, padded text, empty arrays, and optional fields that do not matter for your workflow.

This guide shows how to clean API responses with Forge Json so the output is easier to store, compare, and send into another API step.

This is a common pattern when you need to normalize JSON for databases, queues, automation workflows, or review tools.

๐Ÿ’ก Tip

Paste your JSON into Forge Json and let Clean JSON remove noise before the data moves downstream.

This guide is for developers, automation builders, and data teams working with third-party API payloads.

When to Use This

This approach is a good fit if:

  • your JSON contains null, empty strings, padded text, or unused arrays
  • you need clean JSON for APIs, databases, or pipelines
  • you want repeatable JSON normalization instead of one-off scripts

Before and After

Before: user profile data with extra whitespace and empty optional fields

{
  "users": [
    {
      "name": "  Alice Johnson  ",
      "phone": null,
      "bio": "Software engineer   ",
      "tags": []
    }
  ]
}

After: compact user data that is easier to store and compare

{
  "users": [
    {
      "bio": "Software engineer",
      "name": "Alice Johnson"
    }
  ]
}

If you also need to transform e-commerce orders or merge JSON configuration files, the same pipeline approach can help you turn unreliable input into reusable output.

Why API JSON Gets Messy

Third-party APIs often serve general-purpose payloads. One endpoint may support many clients, product states, and optional profile fields, so the response includes placeholders that are not useful for your workflow.

That becomes painful when you need:

  • clean records for storage or search
  • stable output for comparing changes over time
  • fewer empty values before sending data downstream
  • predictable JSON for automation pipelines

Without a repeatable cleanup workflow, this usually turns into scattered cleanup code that is hard to audit and easy to forget.

The raw JSON example below shows user records with padded strings, null values, empty strings, empty arrays, and nested optional fields.

How to Fix It with Forge Json

Forge Json's Clean JSON utility can apply a practical cleanup workflow from a small set of explicit rules.

You can copy this setup directly:

{
  "removeNulls": true,
  "removeEmptyStrings": true,
  "removeEmptyArrays": true,
  "trimStrings": true,
  "sortKeys": true
}

For this example, the workflow produces a short set of useful steps:

  1. Remove null fields such as phone and apartment.
  2. Remove empty strings and empty arrays that do not carry useful data.
  3. Trim padded strings and sort keys for stable output.

Result

You end up with:

  • trimmed strings
  • fewer empty optional fields
  • stable key ordering
  • cleaner JSON for storage, automation, or review

If the cleanup removes too much, run it again with fewer rules enabled. Smaller cleanup passes are usually easier to review and safer to reuse.

The support material below shows the raw API response, cleanup configuration, and final cleaned output.

This pattern works well for API response cleanup and can be reused across similar JSON workflows.

Related JSON workflows:

Use the example panel below to open this sample input and generated workflow directly in the editor.

FAQ

How do I remove null values from JSON?

You can remove null values by filtering fields programmatically or using a JSON cleanup tool that removes empty or unused fields automatically.

Why should I clean API responses?

Cleaning API responses reduces bugs, simplifies downstream logic, and ensures consistent data for storage and processing.

What is JSON normalization?

JSON normalization means transforming data into a consistent structure by removing noise, standardizing fields, and formatting values predictably.

Support material

Practical example and product context

Use these examples to understand the transformation and apply the same workflow in your own JSON tasks.

Example Transformation

Input
1{
2 "users": [
3 {
4 "id": 1,
5 "name": " Alice Johnson ",
6 "email": "alice@example.com",
7 "phone": null,
8 "bio": "Software engineer ",
9 "tags": [],
10 "address": {
11 "street": "123 Main St",
12 "city": "Portland",
13 "state": "OR",
14 "zip": "97201",
15 "apartment": null
16 },
17 "preferences": {
18 "newsletter": true,
19 "theme": "dark",
20 "language": "",
21 "notifications": null
22 }
23 },
24 {
25 "id": 2,
26 "name": "Bob Smith",
27 "email": "bob@example.com ",
28 "phone": null,
29 "bio": "",
30 "tags": [
31 "developer",
32 "mentor"
33 ],
34 "address": {
35 "street": "456 Oak Ave ",
36 "city": "Seattle",
37 "state": "WA",
38 "zip": "98101",
39 "apartment": ""
40 },
41 "preferences": {
42 "newsletter": false,
43 "theme": " light ",
44 "language": null,
45 "notifications": []
46 }
47 }
48 ]
49}
Config
1{
2 "removeNulls": true,
3 "removeEmptyStrings": true,
4 "removeEmptyArrays": true,
5 "trimStrings": true,
6 "sortKeys": true
7}
โ†“
Output
1{
2 "users": [
3 {
4 "address": {
5 "city": "Portland",
6 "state": "OR",
7 "street": "123 Main St",
8 "zip": "97201"
9 },
10 "bio": "Software engineer",
11 "email": "alice@example.com",
12 "id": 1,
13 "name": "Alice Johnson",
14 "preferences": {
15 "newsletter": true,
16 "theme": "dark"
17 }
18 },
19 {
20 "address": {
21 "city": "Seattle",
22 "state": "WA",
23 "street": "456 Oak Ave",
24 "zip": "98101"
25 },
26 "email": "bob@example.com",
27 "id": 2,
28 "name": "Bob Smith",
29 "preferences": {
30 "newsletter": false,
31 "theme": "light"
32 },
33 "tags": [
34 "developer",
35 "mentor"
36 ]
37 }
38 ]
39}
Built with Cleanup utility
Open the sample input and cleanup workflow in the editor.
View Utility

Related Articles

Continue with another practical guide in the same workflow area.