DevToolsmith

NDJSON MIME Type

application/x-ndjson is the MIME type for newline-delimited JSON (NDJSON, JSON Lines). Here is the Content-Type header to send, the file signature, and how to configure servers and code.

MIME type
application/x-ndjson
Extensions
.ndjson, .jsonl
Content-Type header
application/x-ndjson
Registered
No, a common convention
Compress with gzip
Yes, it is text or uncompressed
Category
Data and text

About JSON Lines (NDJSON) files

One JSON value per line, so files can be streamed, appended to and split without parsing the whole thing. There is no registered type; application/x-ndjson is the most common (Elasticsearch’s bulk API requires it), and application/jsonl is also seen. Responses are often streamed with it, one event per line.

Other types seen for these files: application/jsonl , application/x-jsonlines . Accept them when reading uploads, but send application/x-ndjson yourself.

File signature

NDJSON has no fixed signature: it is data without a magic number, so validate uploads by parsing the content rather than by checking bytes.

Serve .ndjson with the right Content-Type

Response header
Content-Type: application/x-ndjson
nginx (a line in the types { } block of mime.types)
application/x-ndjson ndjson jsonl;
Apache (.htaccess or server config)
AddType application/x-ndjson .ndjson .jsonl
Caddy
@ndjson path *.ndjson *.jsonl
header @ndjson Content-Type "application/x-ndjson"
Check what a server sends
curl -sI https://example.com/file.ndjson | grep -i '^content-type'
# Content-Type: application/x-ndjson

Set the type in code

Node.js (Express)
res.set('Content-Type', 'application/x-ndjson');
// Or make the browser download it:
res.attachment('file.ndjson');
Python
import mimetypes

mimetypes.add_type('application/x-ndjson', '.ndjson')  # if your system doesn't know it
mimetypes.guess_type('file.ndjson')[0]  # 'application/x-ndjson'
Go
mime.AddExtensionType(".ndjson", "application/x-ndjson")
w.Header().Set("Content-Type", "application/x-ndjson")

Accept .ndjson uploads

HTML
<input type="file" accept=".ndjson,.jsonl,application/x-ndjson">

The accept attribute only filters the file picker; users can still choose another file. Listing the extension as well as the type matters, because operating systems don’t always report the type you expect.

Related types

  • .json (application/json): JSON
  • .csv (text/csv): CSV
  • .txt (text/plain): Plain text

More data and text

.tsv , .md , .jsonld , .xml , .yaml , .geojson , .ics , .sql . Look up any extension or type with the MIME type lookup.

Sources

Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.

Frequently asked questions

What is the MIME type for .ndjson files?

application/x-ndjson. You may also see application/jsonl, application/x-jsonlines, which are older or unofficial; send application/x-ndjson. The full header is "Content-Type: application/x-ndjson".

Why does my server send the wrong Content-Type for .ndjson?

Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .ndjson is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".

How can I check that a file really is NDJSON?

NDJSON has no fixed file signature, so the extension and content are all you have. Check that the content is what you expect, for example by parsing it, before trusting an upload.