DevToolsmith

JSON MIME Type

application/json is the MIME type for JSON data. Here is the Content-Type header to send, the file signature, and how to configure servers and code.

MIME type
application/json
Extensions
.json, .map
Content-Type header
application/json
Registered
Yes, with IANA
Compress with gzip
Yes, it is text or uncompressed
Category
Data and text

About JSON files

JSON is always UTF-8 (RFC 8259), so the type has no charset parameter: application/json alone is correct, and ; charset=utf-8 is harmless but ignored. text/json and application/x-json are old unofficial names. Types like application/problem+json and application/geo+json are JSON too; the +json suffix tells generic tools they can parse them.

  • If fetch(…).then(r => r.json()) fails with “Unexpected token <”, the server sent HTML (usually an error or login page) instead of JSON. Check the status code and the Content-Type before parsing.
  • For a JSON API, also send X-Content-Type-Options: nosniff, so a browser never treats a response as HTML.

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

File signature

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

Serve .json with the right Content-Type

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

Set the type in code

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

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

Accept .json uploads

HTML
<input type="file" accept=".json,.map,application/json">

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

  • .ndjson (application/x-ndjson): JSON Lines (NDJSON)
  • .jsonld (application/ld+json): JSON-LD
  • .geojson (application/geo+json): GeoJSON
  • .xml (application/xml): XML

More data and text

.txt , .csv , .tsv , .md , .yaml , .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 .json files?

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

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

Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .json 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 JSON?

JSON 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.