SmartQueryTools

Flatten JSON Files Online

Flatten nested JSON structures in JSON files into a flat table directly in your browser. Nested objects are expanded into prefixed columns — no upload required.

How to flatten JSON files

  1. Drop your JSON file onto the upload area. The tool finds every top-level key that holds a nested object and previews the first 200 rows.
  2. Read the list of nested columns. Each one is shown with the new column names it will produce, such as location → location_site, location_floor.
  3. Click Flatten. The preview switches to the flattened table.
  4. Click Download JSON to save the result, with _flat added to the file name. If the file has no nested objects, the tool says it is already flat and there is nothing to run.

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

A facilities team pulls a device list from a sensor platform API. Each record looks like {"device_id": "th-01", "location": {"site": "Depot A", "floor": 2}, "battery": 87}, and the spreadsheet they report from needs one plain column per field.

Input (JSON)

[
  {
    "device_id": "th-01",
    "location": {
      "site": "Depot A",
      "floor": 2
    },
    "battery": 87
  },
  {
    "device_id": "th-02",
    "location": {
      "site": "Depot A",
      "floor": 1
    },
    "battery": 64
  },
  {
    "device_id": "th-07",
    "location": {
      "site": "Harbour St"
    },
    "battery": 12
  }
]

Settings

  • No options. Every nested object column is expanded one level.

Result

device_idbatterylocation_sitelocation_floor
th-0187Depot A2
th-0264Depot A1
th-0712Harbour StNULL

The location object is replaced by two columns named with an underscore: location_site and location_floor. Plain columns stay first and the expanded columns are added at the end, so battery moves ahead of the location fields. th-07 had no floor key in its location object, so location_floor is null.

Working with JSON files

When the file loads, every key across all records is collected into a schema. A key whose value is an object becomes a struct column with one field per nested key seen anywhere in the file. That is what Flatten expands. Records that lack one of those nested keys get null in the new column, so the output always has the same columns for every row, even when the source objects were uneven.

Flattening goes one level deep per run. For {"customer": {"address": {"city": "Cork"}}} the first run gives a column customer_address that still holds {"city": "Cork"}. Run the tool again on the downloaded file to get customer_address_city. New names join the parent key and the child key with an underscore, not a dot. Keys are kept exactly as written, including spaces, quotes and symbols. MongoDB Extended JSON such as {"_id": {"$oid": "65f1..."}} flattens to a column named _id_$oid.

Arrays are not expanded. A key holding a list, such as "tags": ["a", "b"] or a list of order-line objects, is carried through unchanged as a JSON array in the output. The downloaded file is a JSON array of flat objects, pretty-printed, with the plain keys first and the expanded keys after them. If a nested object has very different keys from one record to the next, it may load as a raw JSON value instead of a struct. It is then left as it is, and Extract JSON Column is the better tool for pulling fields out of it.

Frequently Asked Questions

Does flattening use dot notation such as address.city?

No. Nested keys are joined with an underscore, so address.city becomes a column named address_city.

How do I flatten an array of objects inside each JSON record?

This tool leaves arrays as they are. To give each array item its own row, use the SQL Query tool with UNNEST on that column, then flatten the result.

How many levels of nesting are flattened?

One level per run. Objects nested inside objects become struct columns that you can flatten by running the tool again on the output.

Does flattening change the column order?

Yes. Columns that were already flat come first, in their original order, and the expanded columns are added after them.

What if my file has no nested objects?

The tool reports that no nested structures were detected and that the file is already flat. There is no Flatten button in that case.

Related Tools