Files and data
Treat a file’s MIME label as a hint
Do not treat File.type or a filename extension as proof of content. A file object can carry an inaccurate or empty MIME label; actual parsing and format validation must decide whether it is usable.
Worked example
Node.js example · save as example.mjs and run node example.mjs
const file = new File(["not JSON"], "data.json", {type: "application/json"});
console.log(file.type);
try { JSON.parse(await file.text()); }
catch { console.log("Content is not JSON"); }How it works
The metadata says application/json, but the bytes do not form a JSON value. This separates selection hints and descriptive labels from actual content verification. An importer should report a useful format error rather than trusting the extension alone.
Limits and mistakes
A successful parse still needs schema validation and resource limits. Binary formats may require checking signatures and deeper structure. Do not attempt to prove safety from a few magic bytes when the full parser or consumer has more requirements.
Check the result
Expect application/json followed by Content is not JSON. Include a valid JSON file with an empty MIME label to confirm your tool does not reject good data solely because metadata is missing.
Sources
Reference documentation for the behavior used in this guide: