SmartQueryTools

Trim Whitespace in JSON Files Online

Trim leading and trailing whitespace from all text columns in JSON files, directly in your browser. No upload required.

How to trim Whitespace in JSON files

  1. Drop your file onto the upload area. The tool loads it and reports how many text columns will be trimmed.
  2. Check the column chips. Highlighted columns are text and will be trimmed. Number, date and boolean columns are shown unhighlighted and are left alone.
  3. Click Trim Whitespace. The preview updates to show the trimmed values.
  4. Click Download to save the cleaned file in the same format you uploaded.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Worked example

Wholesale orders were keyed in through a web form, and some product codes and customer names picked up stray spaces. A lookup on product code is failing for those rows.

Input (JSON)

[
  {
    "product_code": " PX-204",
    "customer": "Blue  Harbor Cafe ",
    "qty": 12
  },
  {
    "product_code": "PX-310 ",
    "customer": " Lindqvist AB",
    "qty": 4
  },
  {
    "product_code": "PX-118",
    "customer": "Casa Moreno",
    "qty": 20
  },
  {
    "product_code": "  PX-204",
    "customer": "Blue  Harbor Cafe",
    "qty": 6
  }
]

Settings

  • No options. Every text column is trimmed: product_code and customer.

Result

product_codecustomerqty
PX-204Blue Harbor Cafe12
PX-310Lindqvist AB4
PX-118Casa Moreno20
PX-204Blue Harbor Cafe6

Spaces at the start and end of each text value are removed, so both PX-204 rows now carry the same code and the same customer name. The double space inside "Blue Harbor Cafe" is kept, because only the ends of a value are trimmed. qty is numeric, so it is not touched.

Working with JSON files

JSON from forms and scraped pages often has values like "name": "Ana Ruiz ". Every top-level string field is trimmed across all objects in the array. Numbers, booleans and null values are left as they are, and keys are not changed. A key that is " email" with a leading space keeps that space. Stray spacing is common in data scraped from HTML, where text keeps the indentation of the page layout.

Nested objects and arrays are not trimmed. They are passed through unchanged, and the rest of the file is still trimmed. To trim nested strings, flatten the JSON first so they become top-level columns. The output is a pretty-printed JSON array, and a value of only spaces comes out as an empty string, "". Keys that were missing from an object are written as null. Numbers and booleans are written back as JSON numbers and booleans, not strings.

Frequently Asked Questions

Are strings inside nested JSON objects trimmed?

No. Only top-level string fields are trimmed. Nested objects and arrays of strings are left as they are. Flatten the file first, then trim.

Does trimming change my JSON keys?

No. Only string values are trimmed. Key names, including any spaces in them, are kept as they are. Use Rename Columns to fix a key.

Which characters are removed?

Ordinary space characters at the start and end of each text value. Tabs, line breaks and non-breaking spaces are not removed, and spaces between words are kept.

Can I choose which columns to trim?

No. Every text column is trimmed automatically, and non-text columns are left alone. To trim only some columns, use the SQL Query tool with TRIM on those columns.

Why trim before deduplicating or joining?

Matching is exact, so "PX-204" and "PX-204 " count as different values. Trimming first lets duplicates, lookups and joins match as expected.

Related Tools