JSON5 in Deno: What Works and What Does Not

Deno has no built-in JSON5 parser and the standard library has none either, but the npm package runs unchanged.

We checked on November 29, 2026: the JSR registry has no @std/json5, a JSON5 file cannot be imported as a module, and deno.json5 is not read. What does work is npm:json5, and it took three lines on Deno 2.5.1.

Below are tested samples, the exact error messages Deno prints when you try the other routes, how permissions apply, why Deno's own config is JSONC, and when @std/jsonc is the better answer.

A JSON5 file entering a Deno sandbox through an npm package door while a missing built-in parser slot stays empty

TL;DR: Use import JSON5 from "npm:[email protected]" and read the file with Deno.readTextFile(). There is no @std/json5, no with { type: "json5" } import and no deno.json5. If you only need comments and trailing commas, jsr:@std/jsonc is the official choice.

Deno logo

Does the Deno Standard Library Parse JSON5?

No. The official @std scope on JSR lists 43 packages today, and none is for JSON5. Asking the CLI for it directly settles the question:

$ deno info jsr:@std/json5 error: JSR package not found: @std/json5

That output is from Deno 2.5.1 on November 29, 2026. Deno 2.9.8 (October 21, 2026) is the latest release on GitHub, and we could not run it here, so repeat the command on your version; the JSR scope list above is read live and does not depend on the CLI version. The formats the standard library does cover are worth knowing, because one of them may be all you need:

JSR package Version listed Format
@std/json1.1.0Strict JSON, including streaming parse and stringify
@std/jsonc1.0.3JSON with comments and trailing commas
@std/yaml1.3.0YAML
@std/toml1.0.11TOML
@std/ini0.225.2INI

The JSR registry does hold one package named json5, published under the @nodejs-loaders scope. Its compatibility data on JSR marks it as working on Node.js only, with Deno and Bun both false, so it is not an answer for Deno. An older third-party port exists on the deno.land/x registry (version 1.0.0, a wrapper that imports the npm package through Skypack); that registry is now read-only. We did not test it and recommend the npm package, which is the maintained reference implementation described in the JavaScript guide.

npm logo

Using npm:json5

Deno runs npm packages through the npm: specifier, so the same package Node.js uses works with no install step and no node_modules folder. The version at the time of writing is 2.2.3. Given this config.json5:

{ // Server settings name: 'api', port: 8080, tags: ['a', 'b',], big: 0xFF, half: .5, inf: -Infinity, }

This main.ts reads it, parses it, writes it back, and shows what a syntax error looks like:

import JSON5 from "npm:[email protected]"; const text = await Deno.readTextFile("./config.json5"); const cfg = JSON5.parse(text); console.log(cfg); console.log(JSON5.stringify(cfg, null, 2)); try { JSON5.parse("{a:}"); } catch (e) { console.log(e.name + ": " + e.message, e.lineNumber, e.columnNumber); }

Run with deno run --allow-read main.ts. Real output from Deno 2.5.1:

{ name: "api", port: 8080, tags: [ "a", "b" ], big: 255, half: 0.5, inf: -Infinity } { name: 'api', port: 8080, tags: [ 'a', 'b', ], big: 255, half: 0.5, inf: -Infinity, } SyntaxError: JSON5: invalid character '}' at 1:4 1 4

The first block is Deno's own pretty-printer (console.log shows strings in double quotes); the second is stringify, which writes single quotes, no quotes on keys that do not need them, and a trailing comma on every indented level. The error carries lineNumber and columnNumber, so you can point a user at the spot.

Pin it in deno.json

deno add writes an import map entry, after which the bare name json5 resolves in your code:

$ deno add npm:json5 Add npm:[email protected] // deno.json afterwards { "imports": { "json5": "npm:json5@^2.2.3" } }

With that entry in place, import JSON5 from "json5" works in the project; we ran it and JSON5.parse("{a:1,}") returned { a: 1 }. The same imports map is also where you would pin a different version for every file at once.

Types

Under deno check, JSON5.parse() is untyped, so assigning its result to { a: number } compiles without complaint (we ran it). That means a wrong key is a run-time surprise. Validate the shape yourself, as in the schema validation tutorial, and see the TypeScript guide for patterns.

Code file icon

Importing a .json5 File: Not Supported

Deno's documentation says it supports with { type: "json" } for importing JSON. That attribute is for JSON only. We tried each way of importing the file above on Deno 2.5.1, and these are the messages:

Import Result
import c from "./config.json5" Expected a JavaScript or TypeScript module, but identified a Unknown module. Importing these types of modules is currently not supported.
import c from "./config.json5" with { type: "json" } Expected a Json module, but identified a Unknown module.
import c from "./config.json5" with { type: "json5" } The import attribute type of "json5" is unsupported.
import t from "./config.json5" with { type: "text" } The import attribute type of "text" is unsupported. with the hint run with --unstable-raw-imports

The last row points to a workable route. With the unstable flag, Deno can import the file as text, and you parse the text yourself. We ran this and it printed 8080:

import JSON5 from "npm:[email protected]"; import text from "./config.json5" with { type: "text" }; console.log(JSON5.parse(text).port); // deno run --unstable-raw-imports raw.ts

The flag is unstable. The flag is not listed on Deno's unstable-flags documentation page, so its behavior may change or move. For production, prefer Deno.readTextFile(), which is stable and shown above.

For a runtime that does import the format natively, see JSON5 in Bun.

Settings icon

deno.json vs deno.jsonc

Deno's own configuration file is JSON or JSONC, not JSON5. Its documentation says it "supports .json and .jsonc extensions, so with deno.jsonc you can add comments and trailing commas," and that it detects either file in the current directory or any parent. A deno.json5 is not looked for. We made a folder containing only a valid deno.json5 with a task in it and ran deno task:

error: deno task couldn't find deno.json(c) or package.json. See https://docs.deno.com/go/config

So the answer for Deno's config is deno.jsonc. JSONC gives you comments and trailing commas, which covers most of what people want from JSON5 in a config file; it does not give you unquoted keys, single-quoted strings, hex numbers or multi-line strings. The trade-offs between the two formats are laid out in JSON5 vs JSONC.

The same gap shows up in the tooling. On Deno 2.5.1, deno fmt --check config.json5 answers error: No target files found., and the --ext list for deno fmt names json and jsonc but not JSON5. To format a JSON5 file, use a formatter that knows the format.

Your application config is another matter: Deno does not care what format your program reads, so an app can load its own app.json5 with npm:json5 while the project's deno.jsonc stays JSONC. See the config guides for tools that do accept JSON5.

Code icon

A Loader With Useful Error Messages

A config loader has three ways to fail: the file is missing, the text is not valid JSON5, or it is valid but not an object. Each deserves its own message, and the npm package's error properties make the second one precise. This version distinguishes all three:

import JSON5 from "npm:[email protected]"; export async function loadConfig(path: string): Promise<Record<string, unknown>> { let text: string; try { text = await Deno.readTextFile(path); } catch (e) { if (e instanceof Deno.errors.NotFound) throw new Error(`${path}: file not found`); throw e; } try { const value = JSON5.parse(text); if (value === null || typeof value !== "object" || Array.isArray(value)) { throw new Error("top level must be an object"); } return value; } catch (e) { if (e instanceof SyntaxError) { const err = e as SyntaxError & { lineNumber: number; columnNumber: number }; throw new Error(`${path}:${err.lineNumber}:${err.columnNumber} ${err.message}`); } throw e; } }

Run against a good file, a missing file and a file containing { a: 1, b: } on two lines, with deno run --allow-read=. loader.ts, the output was:

8080 ./missing.json5: file not found ./bad.json5:2:5 JSON5: invalid character '}' at 2:5

The line and column come from the parser, not from a search of your own, and the permission was scoped to the current folder rather than granted wholesale. Common parse failures and their fixes are collected on the parse errors page.

Lock icon

Permissions

Deno runs in a sandbox. Reading your config file is a file read, so it needs --allow-read. Without it, this is what we got:

$ deno run main.ts error: Uncaught (in promise) NotCapable: Requires read access to "./config.json5", run again with the --allow-read flag

Grant the narrowest scope that works: --allow-read=./config.json5 allows exactly that file, which is the right setting for a program whose only file access is its config. Deno's security documentation says -A grants everything and turns the sandbox off entirely, and advises reaching for it sparingly. Parsing text that is already in memory needs no permission at all, since the parser does no I/O; the first run of an npm: import downloads the package from the npm registry, and Deno's security documentation says no --allow-net is needed to fetch the modules in a program's static import graph, npm and JSR packages included.

Parsing text from an untrusted source is a parsing question, not a permission one; see the security tutorial.

Compare icon

Which Route to Pick

You need Use
Real JSON5: unquoted keys, single quotes, hex, Infinitynpm:json5
To write JSON5 back outnpm:json5 (stringify)
Only comments and trailing commas, no third-party codejsr:@std/jsonc
Deno's own config with commentsdeno.jsonc
Code that must run on both Deno and Bunnpm:json5; Bun's built-in does not exist on Deno

@std/jsonc: the official lighter option

We ran jsr:@std/jsonc@1 (version 1.0.3). It accepts a comment and a trailing comma, and it rejects an unquoted key:

import { parse } from "jsr:@std/jsonc@1"; console.log(parse('{/*c*/ "a":1,}')); // { a: 1 } try { parse("{a:1}"); } catch (e) { console.log(e.name + ": " + e.message); } // SyntaxError: Cannot parse JSONC: unexpected token "a" in JSONC at position 1

It is a good fit when you control the file and can write quoted keys. It is the wrong tool for a file written by someone who expects JSON5 to work, because the first unquoted key fails.

JSON5 in Deno: Common Questions

Does Deno support JSON5 natively?

No. There is no built-in parser and no @std/json5 package. Use npm:json5.

Can I name my config deno.json5?

Not for Deno's own settings: it reads deno.json or deno.jsonc. In our test a folder with only deno.json5 was not found.

Why does my import fail with "Unknown module"?

Deno recognizes JSON, JavaScript and TypeScript modules, not JSON5. Read the file and parse it, as shown above.

Does it need --allow-net?

Not to parse. In our runs only --allow-read was required, to read the file. Deno fetched the npm package itself on the first run.

Is there a faster alternative on Deno?

We did not measure one. For benchmarks and a discussion of parse cost on large files see the performance tutorial.