What is MIME type "application/x-ndjson"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

The MIME type application/x-ndjson represents files that use newline delimited JSON. In these files, each line is an independent JSON object, making data parsing efficient and straightforward.

A file with the NDJSON extension is plain text. Every line holds a valid JSON record. This allows programs to process data one record at a time without loading the entire file into memory.

This format is popular in environments where data is continuously updated or recorded. Learn more about JSON on Wikipedia.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: application/x-ndjson    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="application/x-ndjson">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'application/x-ndjson');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

How does application/x-ndjson differ from standard application/json?

While standard application/json requires the entire file to be a single valid JSON object or array, application/x-ndjson treats every line as an independent JSON object. This allows for streaming and processing massive datasets line-by-line without loading the entire file into memory.

How do I configure Apache or Nginx to serve .ndjson files correctly?

You must explicitly map the extension to the MIME type. For Apache, add AddType application/x-ndjson .ndjson to your configuration or .htaccess. For Nginx, add application/x-ndjson ndjson; inside your mime.types file or types block.

What is the relationship between .ndjson and .jsonl files?

They are functionally identical. Both extensions refer to Newline Delimited JSON (also known as JSON Lines). While .ndjson is often associated with the application/x-ndjson MIME type, you may also see .jsonl used for the same data structure in different libraries or contexts.

How do I parse application/x-ndjson data in JavaScript?

Since the file is not a single valid JSON object, you cannot use JSON.parse() on the whole string. Instead, you should split the raw text by the newline character (\n) and map JSON.parse() over each resulting line, or use a streaming reader to process lines as they arrive.

What happens if a JSON object inside the file spans multiple lines?

The file will fail to parse correctly as application/x-ndjson. The strict requirement of this format is that every newline character (\n) marks the end of a record. All JSON data for a single record must be compacted onto a single line.

Is application/x-ndjson an official IANA standard?

The x- prefix indicates that it is a non-standard or experimental type, though it is the de facto standard for Newline Delimited JSON. There is also a similar format often referred to as application/jsonl or application/x-jsonlines, but application/x-ndjson is widely recognized in the developer community.

Why would I use NDJSON instead of CSV?

NDJSON is superior to CSV when your data is hierarchical or includes nested arrays and objects, which are difficult to represent in flat columns. It retains the structure of JSON while offering the append-friendly, row-based processing benefits of CSV.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.