How to Parse JSON in Python: Simple Guide (2026)
Parse JSON in Python using json.loads() for strings and json.load() for files. Complete guide with code examples, error handling, nested data, and real-world use cases.
Turn JSON Lines or NDJSON into one valid JSON array. Paste data or upload a file, catch malformed lines, preview the result, and download it without uploading your data.
or drag and drop a .jsonl, .ndjson or .txt file here
{"id": 1, "name": "Alice", "role": "admin"}
{"id": 2, "name": "Bob", "role": "editor"}
{"id": 3, "name": "Carol", "role": "viewer"}[
{
"id": 1,
"name": "Alice",
"role": "admin"
},
{
"id": 2,
"name": "Bob",
"role": "editor"
},
{
"id": 3,
"name": "Carol",
"role": "viewer"
}
]| Feature | JSONL / NDJSON | JSON | CSV |
|---|---|---|---|
| Structure | One JSON value per line | Single root array/object | Header row + data rows |
| Streaming | Yes - line by line | No - standard parsers read the whole document | Yes - row by row |
| Nested Data | Supported per line | Fully supported | Not supported |
| File Extension | .jsonl or .ndjson | .json | .csv |
| Common Use | Logs, ML datasets, BigQuery exports, Elasticsearch bulk | APIs, web apps, configs | Spreadsheets, databases |
| Human Readable | Moderate | Good (when formatted) | Excellent |
| Append-Friendly | Yes - just add lines | No - must rewrite array | Yes - just add rows |
Paste JSON Lines or NDJSON, or upload a file up to 15 MB.
Turn line validation, empty-line skipping and pretty-printing on or off.
The JSON array appears as you type. Copy it or download the .json file.
Converting JSONL to JSON in Python is simple using the built-in json module. Read each line from the JSONL file, parse it with json.loads(), and write it straight to the output file with commas between records and brackets around the whole thing. Because no list of records is built up, memory use stays flat even for multi-gigabyte files. Perfect for converting streaming data, log files, or machine learning datasets into standard JSON format for analysis or API consumption.
import json
# Stream JSONL to a JSON array: each record is written as soon as it is read,
# so memory use stays flat no matter how big the file is.
count = 0
with open("data.jsonl", encoding="utf-8") as src, open("output.json", "w", encoding="utf-8") as dst:
dst.write("[")
for line in src:
line = line.strip()
if not line:
continue # skip blank lines
record = json.loads(line) # raises on a malformed line
dst.write(",\n " if count else "\n ")
dst.write(json.dumps(record, ensure_ascii=False))
count += 1
dst.write("\n]\n" if count else "]\n")
print(f"Converted {count} JSONL lines to JSON array")Converting JSONL to JSON in Node.js uses the fs module and readline for efficient line-by-line processing. Read the JSONL file, parse each line with JSON.parse(), and write each record to a write stream with JSON.stringify() as soon as it is read. Because records are never collected into one big array, this handles large files without loading everything into memory. Ideal for backend services, data transformation pipelines, or converting API responses from JSONL format to standard JSON arrays.
const fs = require("fs");
const readline = require("readline");
const { once } = require("events");
// Stream JSONL to a JSON array without holding every record in memory
async function jsonlToJson(inputPath, outputPath) {
const rl = readline.createInterface({
input: fs.createReadStream(inputPath),
crlfDelay: Infinity,
});
const out = fs.createWriteStream(outputPath);
const write = async (chunk) => {
if (!out.write(chunk)) await once(out, "drain"); // respect backpressure
};
let count = 0;
await write("[");
for await (const line of rl) {
if (!line.trim()) continue;
const record = JSON.parse(line); // throws on a malformed line
await write((count ? ",\n " : "\n ") + JSON.stringify(record));
count++;
}
await write(count ? "\n]\n" : "]\n");
out.end();
await once(out, "finish");
console.log(`Converted ${count} lines to JSON array`);
}
jsonlToJson("data.jsonl", "output.json");JSONL is better for streaming because you can read one line at a time without loading the whole file into memory. This makes it perfect for processing logs, large datasets, or real-time data feeds where you process records as they arrive.
Standard JSON arrays are better for tools that expect a JSON array input, like most data analysis tools, Pandas, and REST APIs. They need the data wrapped in brackets with commas between objects.
Convert when your downstream tool doesn't support JSONL natively. If you're loading data into a web app, sending it to an API, or importing into a tool that expects standard JSON, you need to convert from JSONL to a JSON array first. If the resulting array is too large for that tool or API, break it into smaller files with the JSON File Splitter.
Most conversions happen because the next step in your workflow expects standard JSON format, not line-delimited records. When you need to go the other way, the JSON to JSONL converter turns an array back into one record per line.
If one line is malformed (missing bracket, trailing comma, unquoted key), most converters either fail entirely or silently drop that line. This is the #1 problem users hit when converting JSONL files. This tool lists every failing line with its line number and the parser error, and holds back the output until the lines are fixed.
How to find it: paste or upload the file here and read the error list, which names each bad line. Don't rely on VS Code's built-in JSON validator for .jsonl files: it treats the whole file as one JSON document, so it flags every line after the first even when each line is fine. To browse the file itself and filter it down to just the invalid lines, open it in the JSONL Viewer.
Or run jq -c . yourfile.jsonl in the terminal. jq stops at the first parse error and reports its line and column, so fix that line and run it again to find the next one.
Fix the malformed line and the output appears automatically. If you just want the good records, turn off Validate lines in Conversion settings: invalid lines are skipped and a notice tells you how many were dropped.
After converting JSONL to a JSON array, open the result in an editor that handles validation and large nested files well.
The tool runs in the browser so there's no server upload. Your data stays on your machine, which is great for privacy but means the whole file has to fit in browser memory. To keep the page responsive, this converter accepts JSONL input up to 15 MB; larger uploads are rejected with a message.
For files over 15 MB, split them first or convert locally. The quick Python one-liner is: python3 -c "import json; print(json.dumps([json.loads(l) for l in open('file.jsonl') if l.strip()]))" > output.json
That one-liner builds the whole list in memory, so it needs RAM roughly proportional to the file size. For files bigger than your available memory, use the streaming Python or Node.js script in the code examples above: they write each record to the output as soon as it is read, so memory use stays flat.
Parse JSON in Python using json.loads() for strings and json.load() for files. Complete guide with code examples, error handling, nested data, and real-world use cases.
Read JSON files in JavaScript with fetch(), FileReader, Node.js fs, or imports. Includes browser and server examples with error handling.