🍋
Menu
.ndjson Data

NDJSON(换行符分隔的 JSON)

NDJSON 是一种格式,其中每行是一个有效的 JSON 对象,由换行符分隔。这种简单的约定支持流式处理、逐行处理和追加写入,无需解析整个文件。它广泛用于日志文件、数据管道和 API 流传输。

MIME 类型

application/x-ndjson

类型

文本

压缩

无损

优点

  • + Streamable — process one record at a time without loading the entire file
  • + Appendable — add new records by appending lines
  • + Works with Unix tools (grep, head, tail, wc)
  • + Standard for Elasticsearch bulk, BigQuery, and data pipelines

缺点

  • No standard for the overall file (no top-level schema)
  • Cannot represent a single JSON object spanning multiple lines
  • Less compact than binary formats for large datasets

何时使用 .NDJSON

在日志文件、流式数据、批量 API 请求以及任何逐行 JSON 处理有益的场景中使用 NDJSON。

技术细节

NDJSON 文件中的每行是一个完整、独立的 JSON 值(通常是对象),以 \n 结尾。记录之间没有包裹数组或逗号,使其可以轻松地追加、流式处理和使用 Unix 工具处理。

历史

NDJSON(也称为 JSON Lines 或 JSONL)源于流式传输 JSON 记录的实际需求。ndjson.org 规范于 2014 年正式化了该约定。它被 Elasticsearch 批量 API、BigQuery 和 OpenAI 的 API 使用。

从 .NDJSON 转换

转换为 .NDJSON

相关格式