解析 NDJSON (Newline-Delimited JSON)
NDJSON stores one JSON object per 行, enabling streaming 和行-通过-行过程. 常见在 logs, API streaming, 和大 数据 pipelines.
- 1
NDJSON (also JSONL) puts one 完整 JSON object 开每个行, 具有否 commas 或 wrapping 数组. Advantages: streamable (处理行 通过行), appendable (添加新 lines 无 rewriting), 故障-tolerant (one 坏行 不 invalidate rest). 常见在 记录 files, Kafka, 和 BigQuery exports.
- 2 JSON 验证器 →
验证 each line as a separate JSON object. Unlike regular JSON, you cannot parse the entire file as one value — split by newlines and validate each line independently. Skip empty lines and report invalid lines with their line number.
- 3 JSON 格式化器 →
格式化 individual JSON objects from the NDJSON stream. Each line is a standalone JSON object — format it for inspection. This is useful for debugging log entries or API streaming responses.
- 4
过程 NDJSON: 读取行 通过行 ( 不加载整个 file 为内存), 解析每个行 as JSON, 处理解析错误 per 行 (记录和 continue 或 abort), 处理 object. 为大 files, use streaming 读者 (Node.js readline, browser ReadableStream). 为输出, 写入每个结果 as 新 NDJSON 行.
常见问题
- NDJSON vs JSON 数组 — 哪个到 use?
- Use NDJSON 为 streaming, logs, 和大 datasets (每个行 是 independent, 能够是 appended). Use JSON 数组为 小 datasets 该 need 到是 loaded 整个 (atomic, easier 到验证). NDJSON 是 better 为大 数据; JSON arrays 是 better 为配置.
- 如何 I 处理无效 lines 在 NDJSON?
- 解析 each line independently and handle errors per line. Options: skip and log (fault-tolerant), abort on first error (strict), or collect all errors and report at end. For logs, skip and log the error line. For data import, abort to ensure data integrity.