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
Content-Type: application/x-ndjson
application/x-ndjson ndjson jsonl;
AddType application/x-ndjson .ndjson .jsonl
@ndjson path *.ndjson *.jsonl
header @ndjson Content-Type "application/x-ndjson"
curl -sI https://example.com/file.ndjson | grep -i '^content-type'
# Content-Type: application/x-ndjson
Set the type in code
res.set('Content-Type', 'application/x-ndjson');
// Or make the browser download it:
res.attachment('file.ndjson');
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'
mime.AddExtensionType(".ndjson", "application/x-ndjson")
w.Header().Set("Content-Type", "application/x-ndjson")
Accept .ndjson uploads
<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
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.