Flatten JSON to JSONL

Extract and flatten nested JSON objects and arrays into JSONL (JSON Lines) format. Each record becomes a separate line. 100% client-side.

Input JSON

Drop a .json file here, or click to browse

Supports .json, .txt

Output JSONL

Paste or drop nested JSON to flatten into JSONL

What is JSON Flattening?

JSON flattening is the process of transforming a deeply nested JSON structure into a flat, line-by-line format. Nested object keys are converted to dot notation (e.g., address.city), and arrays of objects are expanded so each element becomes its own record in JSONL format.

This is especially useful when you have API responses or database exports with complex nesting, and you need to convert them into a flat tabular format for machine learning training, CSV conversion, or streaming data pipelines that expect one record per line.

Two ways to flatten an array — pick by destination

Nested objects flatten one obvious way (dot-joined keys), but arrays force a real decision. The right strategy depends on where the flattened data is headed:

Strategy[{"sku":"A"},{"sku":"B"}] becomesChoose when
Index expansionitems.0.sku = A, items.1.sku = B — one row, more columnsRow count must stay identical to the input; arrays are short and bounded
Explode into rowsTwo rows, each with items.sku — more rows, stable columnsFeeding SQL or analytics where each array element is really its own record
Keep as JSON stringitems = "[{\"sku\":\"A\"},...]" — one opaque cellThe array is metadata you'll re-parse later, not data to query now

How to Flatten JSON to JSONL

Flattening JSON to JSONL extracts records from nested structures and converts each record into a separate JSONL line. If your JSON contains an array of objects, each array element becomes one line. Nested object keys are flattened into dot notation.

Our tool works entirely in your browser. No data is sent to any server. Paste your nested JSON or drag and drop a file, and the flattened JSONL output appears instantly. Parent-level fields are automatically merged into each record.

The output is valid JSONL with one compact JSON object per line. You can copy the result to your clipboard or download it as a .jsonl file, ready for machine learning, data pipelines, or database import.

Before and after

A realistic nested record and its index-expanded flat form. Note how the separator choice matters: with dots, a literal key like "config.debug" in the source would collide with the flattened path config.debug — if your keys contain dots, switch the separator to underscore:

// Before — nested record:
{"user": {"id": 7, "address": {"city": "Osaka", "zip": "530-0001"}}, "tags": ["vip", "beta"]}


// After — flattened with dot separator, arrays index-expanded:
{"user.id": 7, "user.address.city": "Osaka", "user.address.zip": "530-0001", "tags.0": "vip", "tags.1": "beta"}

Flattening is the standard preprocessing step before CSV or Excel export — those formats are tabular and can't represent nesting. Deeply nested inputs can produce very wide outputs, so flatten a sample first and sanity-check the column count before processing the full file.

Common Use Cases

API Response Processing
Flatten nested API responses into JSONL for easier parsing, logging, and downstream processing in data pipelines.
ETL Data Transformation
Extract records from complex JSON exports and flatten them into JSONL for loading into databases or data warehouses.
ML Dataset Preparation
Convert nested JSON datasets into flat JSONL records required by OpenAI, Hugging Face, and other ML training platforms.
Log & Analytics Processing
Flatten structured log files with nested metadata into JSONL for analysis with tools like grep, jq, or Elasticsearch.
Test Data Generation
Flatten complex JSON API mock responses into individual JSONL records for use as test fixtures in automated testing suites.
Database Migration
Flatten nested document-style JSON exports from MongoDB or CouchDB into flat JSONL records for import into relational databases like PostgreSQL.

Common Errors & Solutions

No Records Found to Flatten

This error occurs when the input JSON is a primitive value (string, number) or an empty object/array. The tool needs objects or arrays of objects to extract records. Ensure your JSON contains at least one object with key-value pairs.

Dot Notation Key Conflicts

If your JSON has a key like "user.name" at the top level and also a nested {"user":{"name":"value"}}, both flatten to the same dot-notation key. The nested value will overwrite the top-level one. Rename conflicting keys before flattening.

Circular References in JSON

While standard JSON cannot contain circular references, some JSON generators may produce very deeply nested structures that resemble them. The tool handles deep nesting up to a reasonable depth but will stop flattening if the structure exceeds safe limits.

Frequently Asked Questions

How does the flattening work for nested objects?

Nested object keys are converted to dot notation. For example, {"user":{"address":{"city":"NYC"}}} becomes {"user.address.city":"NYC"}. This makes deeply nested data accessible as flat key-value pairs.

What happens to arrays in the JSON?

If the JSON contains an array of objects, each object becomes a separate JSONL line. Arrays of primitives (strings, numbers) are serialized as JSON strings within the flattened output. The tool automatically detects the main array to expand.

Is my data safe when flattening?

Yes. All flattening happens locally in your browser. No data is sent to any server. Your JSON content never leaves your device.

Can I flatten JSON with mixed nesting levels?

Yes. The tool handles any level of nesting. Top-level scalar fields are merged into each record, nested objects use dot notation, and the largest array of objects is expanded into individual JSONL lines.

How are null and undefined values handled during flattening?

Null values are preserved as null in the flattened output. JSON does not have an undefined type, so you will not encounter undefined values. Empty objects are flattened to nothing (no keys are generated), and empty arrays are serialized as empty JSON arrays.

Can I flatten multiple JSON files at once?

Currently, the tool processes one JSON input at a time. To flatten multiple files, process them one by one. For batch operations, consider using command-line tools like jq in combination with this tool for visual verification.

What is the maximum nesting depth the tool supports?

The tool supports nesting depths commonly found in real-world JSON data (typically up to 20+ levels). There is no hard-coded depth limit, but extremely deep nesting may produce very long dot-notation keys in the output.

How does this tool differ from JSON to JSONL conversion?

JSON to JSONL simply takes each element of a top-level array and puts it on a separate line. Flatten JSON to JSONL goes further by expanding nested structures, converting nested keys to dot notation, and merging parent-level fields into each record. Use flatten when you need to extract records from deeply nested JSON.

Related tools & guides