JSON File
Definition
JSON stands for JavaScript Object Notation. Douglas Crockford described it in the early 2000s, and it is now specified by RFC 8259 and ECMA-404, which agree on a very small grammar. An object is a set of name and value pairs in braces, an array is an ordered list in square brackets, and values are strings in double quotes, numbers, the literals true, false and null, or further objects and arrays. The strictness is the point: single quotes are not allowed, keys must be quoted, a trailing comma after the last element is a syntax error, and comments do not exist. RFC 8259 requires the encoding to be UTF-8 for data exchanged between systems, so there is no charset parameter on its content type — application/json is complete on its own.
Why It Matters
Serving JSON with the wrong content type is the single most common hosting mistake with the format. A file delivered as text/plain still parses if you fetch it and call JSON.parse yourself, but browser developer tools stop offering the collapsible viewer, and some client libraries reject the response outright rather than guess. The other trap is cross-origin access. A page at example.com fetching data from another host gets nothing back unless the response carries Access-Control-Allow-Origin, and the error in the console names CORS rather than the file, which sends people hunting in the wrong place. Size discipline pays too: JSON is verbose and repetitive, so it compresses hard — a 900 KB feed usually drops below 90 KB once Brotli or gzip is applied.
How It Works
A JSON file is served with Content-Type: application/json, and a browser asked to open it directly will show it in a built-in viewer rather than download it. Code reaches it with fetch, awaiting response.json(), which parses the body into ordinary objects and arrays. When that request crosses origins, the browser first checks the response headers for Access-Control-Allow-Origin and discards the body if the header is missing or does not match. Caching is worth thinking about at the same time: a data file that changes daily wants a short Cache-Control max-age, while one that never changes can take a long one and a version number in the filename. Because a static host serves whatever bytes were uploaded, a JSON file is a read-only endpoint — fine for configuration, catalogues and feeds, useless for anything that needs to accept a write.
Real-World Example
A price comparison widget is published at rates.99helpers.site as a single HTML page that fetches rates.json from the same address on load. Keeping the data in a separate 40 KB file means the daily update is a one-file upload rather than an edit to the page, and the page itself stays cached. Because both files sit on the same origin, no CORS configuration is needed at all. When a bad export once broke the widget, 99helpers version history put the previous rates.json back in a single click, and the page recovered on the next refresh.
Common Mistakes
- ✕Serving the file as text/plain or application/octet-stream — some clients refuse it, and the browser's JSON viewer disappears
- ✕Writing JavaScript object syntax rather than JSON — unquoted keys, single quotes and trailing commas are all valid JavaScript and all invalid JSON
- ✕Expecting a cross-origin fetch to work without the Access-Control-Allow-Origin header — the request succeeds at the network level and the browser throws the body away
- ✕Publishing personal data in a JSON file because it looks technical — a public URL is public, and search engines index JSON files like anything else
Related Terms
CORS
Cross-Origin Resource Sharing is a set of HTTP headers that lets a server say which other origins are allowed to read its responses from JavaScript. Without those headers the browser fetches the file but refuses to hand the contents to the calling script.
REST API
A way of exposing a service over HTTP where each thing you can act on has its own URL, and the HTTP method says what you are doing to it. GET reads, POST creates, PUT replaces, DELETE removes.
XML File
XML is a text format for structured data built from nested, named elements with attributes. It is strict about being well formed: one unclosed tag or one bare ampersand and a conforming parser stops rather than guessing.
Character Encoding
A character encoding is the rule that maps the bytes in a file to the characters a person reads. Get it wrong and nothing errors — the text simply comes out as the wrong characters.
Cache-Control
The HTTP response header that tells browsers and caches whether they may keep a copy of a file, for how long, and who is allowed to. It is the single biggest lever over how fast a site feels on a second visit.
Put a file online in seconds
Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.
Host a file free →