What is the maximum size of a JSON file?

Dark navy cover card with the title 'What is the maximum size of a JSON file?' in white and a green accent bar

There is no maximum size for a JSON file in the format itself. The JSON standard leaves limits to each implementation, so the real ceiling comes from whatever reads the file: a JavaScript engine, a server's request body parser or a database column. In practice that ranges from about 100 KB on a default web server to roughly 1 GB in some databases.

What the JSON standard says about the maximum size of a JSON file

The JSON standard sets no maximum file size. Section 9 of RFC 8259 says an implementation "may set limits on the size of texts that it accepts." The same section allows limits on nesting depth, on the range and precision of numbers, and on string length.

A 3 GB file is valid JSON. Whether anything can read it is another matter.

The real limits at each layer

The JSON size limit you hit depends on which layer reads the data first. These are the limits I found in the official docs:

Layer Limit Where it comes from
JSON spec None RFC 8259 leaves it to implementations
Node.js string (Node 13) 1,073,741,799 characters Measured max string length
Node.js string (later versions) 536,870,888 characters Measured max string length
Express express.json() 100kb by default The limit option
MongoDB document 16 mebibytes BSON document size
MySQL JSON column 1GB MySQL JSON type
PostgreSQL field 1 GB Field size limit

The smallest number in the chain wins. A 2 MB payload is fine for MongoDB and Node, but a default Express server rejects it long before either sees it.

Why JavaScript has a hard ceiling

JavaScript's limit is a cap on string length, because JSON.parse needs the whole JSON text as one string. Node exposes the cap as buffer.constants.MAX_STRING_LENGTH, per the Buffer documentation.

That cap has changed between versions. One test across Node.js versions measured 1,073,741,799 characters for Node 13 and 536,870,888 for later releases. A script that parsed a file on Node 13 can fail on the same file after an upgrade.

Cross it and you get this:

Cannot create a string longer than 0x1fffffe8 characters

That message shows up in workflow tools and build scripts whenever someone reads a huge file into memory and parses it. The hex value 0x1fffffe8 works out to 536,870,888, the same newer limit from the table.

Memory usually runs out first. Parsed objects take more space than the raw text, so a browser tab or a small server can stall on files well under the string limit.

Request body limits on servers and APIs

Server frameworks cap request bodies far below any language limit, mostly to stop a client from exhausting memory. In Express, the express.json() middleware has a limit option with a default of "100kb", which "controls the maximum request body size."

A mobile app syncs its records as one JSON array. The body grows past 100 KB, and the server starts returning errors while every small test request still passes. The JSON is fine. The body parser stopped reading it.

You can raise it with express.json({ limit: '5mb' }). Do that on the routes that need it, not globally, so a bad client can't push huge bodies at every endpoint.

Gateways, proxies and serverless platforms add their own payload caps. The request has to fit through every hop.

Database limits for JSON documents

Databases set the most generous limits, but they still exist. MongoDB stores JSON-like data as BSON, and its limits page says the maximum BSON document size is 16 mebibytes.

Relational databases go higher. A MySQL engineering post puts the JSON type's maximum at 1GB, while adding that the ideal size is less than that. PostgreSQL's limits table lists a field size of 1 GB, which covers a json or jsonb value.

Don't store a 1 GB document because the column allows it. Every read and update moves the whole value.

How to find which limit you're hitting

Look at the exact error and where it was raised. Then work down this list:

  1. Check the error source. A "payload too large" response from the server means a body limit. A string length error means the parser.
  2. Measure the payload. Check the file size on disk or the Content-Length of the request, then compare it to the table above.
  3. Shrink it first. Removing whitespace shrinks a pretty-printed file. You can strip it with the JSON minifier, which runs in your browser.
  4. Raise the limit only where it's safe. Change the one route or setting that needs it.
  5. Change the shape if it's still too big. Stream the data or split it into smaller pieces.

A file cut off mid-transfer throws a different error, covered in unexpected end of JSON input.

When a JSON file is simply too big

If your JSON is near any of these limits, the format is usually the wrong shape for the job. Two changes solve most cases.

First, switch to one record per line. The NDJSON format lets you read, split and append records without ever loading the whole file. Second, stream instead of parsing whole. The guide on how to open a large JSON file shows jq and Python streaming that keeps memory flat.

RFC 8259 also allows limits on numbers. Very long numbers can lose precision even in a small file, which is explained in JSON.parse and large numbers.

My take: once a single JSON document regularly passes a few megabytes, stop raising limits and change the format. Every raised limit is one more place a large request can hurt you.

One limitation applies to browser-based tools, including OnlineViewer Dev. Pasted JSON is processed by JavaScript in your tab and never uploaded, so the tab's own string and memory limits apply. For very large files, use a streaming command-line tool.

FAQ

Does the JSON standard limit file size?

No. The JSON standard says an implementation may set limits on the size of texts it accepts, so any cap comes from the parser or platform, not from the format.

How big can a JSON string be in Node.js?

Measured maximum string length was 1,073,741,799 characters in Node 13 and 536,870,888 in later versions. JSON.parse needs the whole text as one string, so that is a hard ceiling for parsing in one call.

What is the default JSON body limit in Express?

express.json() defaults to a limit of 100kb. Larger request bodies are rejected unless you raise the limit option.

How large can a JSON document be in MongoDB?

MongoDB stores documents as BSON, and the maximum BSON document size is 16 mebibytes.

What should I do if my JSON file is too large?

Find which layer rejects it first. Then either raise that limit, stream the file instead of parsing it whole, or split it into one record per line.

Sources