# JSON5 in Bun: Native Imports and Bun.JSON5 | JSON5.dev


Source: https://json5.dev/tools/bun/

---

# JSON5 in Bun: Native Imports and the Bun.JSON5 API

Bun is the one mainstream JavaScript runtime that reads JSON5 without a package: import a `.json5` file, or call `Bun.JSON5.parse()`.

The feature arrived in Bun v1.3.7 on January 27, 2026, was rewritten from Zig to Rust in Bun 1.4, and today parses and stringifies, imports and bundles. It is smaller than the `json5` npm package, though: no reviver, no replacer, no quote option.

This page covers the exact API, the conformance claim and who makes it, what the bundler does with a JSON5 import, the TypeScript types that ship with Bun, a migration checklist from the npm package, and the gotchas.

![A JSON5 config file flowing straight into a Bun runtime with no parser package between them](https://json5.dev/img/hero/tools-bun.png)

**TL;DR:** On Bun 1.3.7 or newer, `import config from "./config.json5"` and `Bun.JSON5.parse(text)` work with no install. `Bun.JSON5.stringify(value, null, space)` writes it back. Bun states that its parser passes 100% of the official test suite. Bring the `json5` npm package only if you need a reviver, a replacer or the `quote` option, or if the same code must also run on Node.js.

[Version and History](#history) [The API](#api) [Importing Files](#imports) [Bundler](#bundler) [Conformance](#conformance) [TypeScript](#typescript) [Migration](#migration) [Gotchas](#gotchas) [FAQ](#faq)

![Bun logo](https://json5.dev/images/tech/bun.svg)

## Which Bun Version, and How It Got Here

Bun announced `Bun.JSON5.parse()` and `Bun.JSON5.stringify()` in the release notes for **Bun v1.3.7, dated January 27, 2026**, under the heading "Native JSON5 Support", together with the ability to `import` a `.json5` file directly. The change itself was a pull request by Dylan Conway (oven-sh/bun #26439), opened January 25 and merged January 26, 2026; it closed a long-standing feature request, issue #3175. The pull request lists 317 unit tests of its own plus 113 cases taken from the official JSON5 test suite.

The first implementation was written in Zig, and the Bun 1.3.14 documentation, which ships inside the `bun-types` package, still said so: "The parser is written in Zig for optimal performance." Bun 1.4 (August 20, 2026) rewrote the runtime in Rust, and the current documentation page, which is headed Bun v1.4.5 (released November 19, 2026), says the parser "is written in Rust". If you read an older tutorial that says Zig, it was correct when it was written. The documented API in the 1.4.5 type package is the same one.

Bun release

Date

What it means for JSON5

v1.3.7

January 27, 2026

`Bun.JSON5` and `.json5` imports first ship

1.4

August 20, 2026

Runtime rewritten in Rust; JSON5 support carried over

v1.4.5

November 19, 2026

The version the current documentation page is written for

**Version floor for your project:** require Bun 1.3.7 or newer. Older releases predate the feature. Pin the version in your CI image or setup step, and check `bun --version` there.

![Bun logo](https://json5.dev/images/tech/bun.svg)

## The Bun.JSON5 API

There are two functions, available on the global `Bun` object and as a named export from the `bun` module. Both spellings are the same object.

### Bun.JSON5.parse(input: string): unknown

Parses a JSON5 string into a JavaScript value. Bun's documentation lists what it accepts: both comment forms, [trailing commas](https://json5.dev/glossary/#trailing-comma) in objects and arrays, unquoted keys (any ECMAScript 5.1 identifier), single- and double-quoted strings, backslash [line continuations](https://json5.dev/glossary/#line-continuation) inside strings, hexadecimal numbers, [leading](https://json5.dev/glossary/#leading-decimal-point) and trailing decimal points, `Infinity` and `NaN` with either sign, and an [explicit plus sign](https://json5.dev/glossary/#explicit-plus-sign). Invalid input throws a `SyntaxError`. The declared signature takes one argument.

``import { JSON5 } from "bun"; const result = JSON5.parse(`{ // This is a comment name: 'my-app', version: '1.0.0', // trailing comma is allowed hex: 0xDEADbeef, half: .5, infinity: Infinity, }`);``

The sample is the example in Bun's own type declarations. We could not run it: Bun is not installed on our test machine, so every Bun snippet on this page is quoted from the documentation, the release notes or the shipped type package rather than executed by us.

### Bun.JSON5.stringify(input: unknown, replacer?: undefined | null, space?: string | number): string | undefined

Converts a value to JSON5. Output is compact unless you pass `space`: a number of spaces per level (clamped between 0 and 10) or a string whose first 10 characters become the indent. Unlike `JSON.stringify`, it keeps `Infinity`, `-Infinity` and `NaN` as literals instead of writing `null`. It returns `undefined` for `undefined`, functions and symbols. The type declaration says the `replacer` argument is "Not supported", and its type allows only `undefined` or `null`.

`console.log(JSON5.stringify({ name: "my-app", version: "1.0.0" })); // {name:'my-app',version:'1.0.0'} console.log(JSON5.stringify({ a: 1, b: 2 }, null, 2)); // { // a: 1, // b: 2, // }`

The compact output is the example on Bun's documentation page, and the indented output is the example in its type declarations. Indented output ends each level with a trailing comma, as the declaration states. The documentation page and the pull request show single-quoted strings, while the type declaration's own example shows `{a:1,b:"two"}`; see the gotchas.

### Round trip with a comment

As with every JSON5 library that is not a [round-trip](https://json5.dev/glossary/#round-trip) editor, a comment is discarded the moment the text is parsed, so parse-then-stringify returns the data but not the annotation. If a tool must edit a file and keep its comments, see [the implementations directory](https://json5.dev/implementations/) for other libraries.

`const data = Bun.JSON5.parse("{ /* keep me */ a: 1 }"); // { a: 1 } - the comment is gone await Bun.write("out.json5", Bun.JSON5.stringify(data, null, 2));`

### What is not in the documented API

A [reviver](https://json5.dev/glossary/#reviver) for `parse` and a replacer for `stringify` are the two things `JSON.parse` and `JSON.stringify` have that Bun's functions do not. On October 24, 2026 the author of the original parser opened a pull request (oven-sh/bun #46747) to add both. It was closed without being merged the same day, and the 1.4.5 type declaration still marks the replacer "Not supported", so treat both as unsupported and check the current documentation before relying on either. `stringify` has no equivalent of the npm package's `quote` option either.

![Code file icon](https://json5.dev/images/icons/code-file.png)

## Importing .json5 Files

Bun's module resolver treats `.json5` as a data module, the same way it treats `.json`, `.toml` and `.yaml`. The file is parsed when it is loaded and the result is the module's default export; top-level properties are also available as named exports. No loader flag, no `bunfig.toml` entry and no import attribute is needed, although Bun's file-types documentation also shows the explicit form `import data from "./data.txt" with { type: "json5" }` for a file with another extension.

`// config.json5 { // Database configuration database: { host: 'localhost', port: 5432, }, tags: ['web', 'api',], } // app.ts import config from "./config.json5"; // the whole object import { database } from "./config.json5"; // a top-level property const cjs = require("./config.json5"); // CommonJS works too const { default: dyn } = await import("./config.json5");`

The documentation covers each form: default import, named imports, `require()` and dynamic `import()` where the parsed value is on `default`. Bun's guide "Import a JSON5 file" shows the same thing in a few lines.

### Hot reloading

Run a server with `bun --hot server.ts` and an edit to an imported `.json5` file is picked up without restarting the process, which makes a commented config file a pleasant thing to tune against a running service. Bun's documentation lists watch mode as supported as well.

**An import is a code path, not a file read.** Anything you import is resolved relative to the importing module and can be bundled into your output. Use an import for config that ships with your code. For a file chosen at run time, such as a user-supplied path, read it with `Bun.file(path).text()` and pass it to `Bun.JSON5.parse()`, so a bad file raises an error you can catch and report.

![Layers icon](https://json5.dev/images/icons/layers.png)

## What the Bundler Does With It

`bun build` parses an imported JSON5 file at build time and emits it as a JavaScript module, so the production bundle carries a plain object literal and no parser. Bun's documentation names three consequences: no JSON5 parsing at run time in production, smaller bundles, and tree shaking of named imports that nothing uses. The same applies to frontend code that Bun bundles for the browser.

`bun build app.ts --outdir=dist`

The practical rule: a `.json5` file you import is frozen into the bundle at build time. Editing it after the build changes nothing in the shipped output. If the file must stay editable by operators after deployment, read it at run time instead.

Other bundlers need a plugin or a loader to understand the format; see the guides for [Vite](https://json5.dev/config/vite/), [webpack](https://json5.dev/config/webpack/), [Rollup](https://json5.dev/config/rollup/) and [esbuild](https://json5.dev/config/esbuild/).

![Checklist icon](https://json5.dev/images/icons/checklist.png)

## The Conformance Claim, Attributed

Bun's documentation states that its parser passes 100% of the official JSON5 test suite and links a translated copy of that suite in the Bun repository that lists every case. That is Bun's own statement, made by the people who wrote the parser, and we have not re-run it. What the pull request itself shows is narrower and checkable: 113 tests drawn from the official suite, plus 317 of Bun's own.

Passing the shared suite is a good sign and not a guarantee, because the suite covers the grammar and a handful of error cases, not every edge of your documents. The suite and what it measures are described on [the conformance page](https://json5.dev/conformance/), and where Bun sits among other parsers is on [the implementations page](https://json5.dev/implementations/).

The grammar Bun implements is the one in [the specification grammar](https://json5.dev/spec/grammar/).

![TypeScript logo](https://json5.dev/images/tech/typescript.png)

## TypeScript Types

Install `bun-types` (or `@types/bun`) and the types arrive with it. We downloaded `bun-types` 1.4.5, the latest on npm today, and read the declarations:

-   `parse(input: string): unknown`, so you must narrow or validate the result before using it.
-   `stringify(input: unknown, replacer?: undefined | null, space?: string | number): string | undefined`.
-   `declare module "*.json5"` types an imported file as `any`, and a matching `declare module "*" with { type: "json5" }` declaration in `import-attributes.d.ts` covers the import-attribute form.

Because an imported file is typed `any` and `parse` returns `unknown`, the type system will not catch a wrong key. Give the data a shape yourself, ideally with a runtime check, as in [the schema validation tutorial](https://json5.dev/tutorials/schema-validation/):

`import raw from "./config.json5"; interface AppConfig { name: string; port: number; } function isAppConfig(v: unknown): v is AppConfig { return typeof v === "object" && v !== null && typeof (v as any).name === "string" && typeof (v as any).port === "number"; } if (!isAppConfig(raw)) throw new Error("config.json5 has the wrong shape"); const config: AppConfig = raw;`

More on TypeScript with this format is in [the TypeScript guide](https://json5.dev/typescript/) and [the TypeScript errors page](https://json5.dev/troubleshooting/typescript-errors/).

![npm logo](https://json5.dev/images/tech/npm.png)

## Migrating From the json5 npm Package

The package in [the JavaScript guide](https://json5.dev/javascript/) is the reference implementation, and Bun's functions are deliberately close to it. For plain config loading the swap is mechanical. Check each row before you delete the dependency.

Feature

`json5` npm package

`Bun.JSON5`

`parse(text)`

![Yes](https://json5.dev/images/icons/yes.png)

![Yes](https://json5.dev/images/icons/yes.png)

`parse(text, reviver)`

![Yes](https://json5.dev/images/icons/yes.png)

![No](https://json5.dev/images/icons/no.png)

`stringify(value, null, space)`

![Yes](https://json5.dev/images/icons/yes.png)

![Yes](https://json5.dev/images/icons/yes.png)

`stringify` with a replacer function or array

![Yes](https://json5.dev/images/icons/yes.png)

![No](https://json5.dev/images/icons/no.png)

`stringify` options object with `quote`

![Yes](https://json5.dev/images/icons/yes.png)

![No](https://json5.dev/images/icons/no.png)

Error carries `lineNumber` and `columnNumber`

![Yes](https://json5.dev/images/icons/yes.png)

Not documented; the documentation says only that a `SyntaxError` is thrown

Imports `.json5` files natively

Only through the package's Node.js `require` hook

![Yes](https://json5.dev/images/icons/yes.png)

Runs on Node.js and Deno

![Yes](https://json5.dev/images/icons/yes.png)

![No](https://json5.dev/images/icons/no.png)

### A safe swap

`// before import JSON5 from "json5"; const config = JSON5.parse(await Bun.file("config.json5").text()); // after: read and parse as before const config = Bun.JSON5.parse(await Bun.file("config.json5").text()); // or, for config that ships with the code, just import it import config from "./config.json5";`

1.  Search the code for a second argument to `parse`, a second or third argument to `stringify`, and any `quote` option. Keep the npm package where any of them appear.
2.  Search for `catch` blocks that read `lineNumber` or `columnNumber`. Those are properties of the npm package's errors.
3.  Compare the written output if another program reads it: the quote character in output differs between sources (see the gotchas).
4.  If the code also runs on Node.js or Deno, keep the npm package there; `Bun.JSON5` does not exist on those runtimes. Our guides for [Node.js](https://json5.dev/nodejs/) and [Deno](https://json5.dev/tools/deno/) show the options.

![Warning icon](https://json5.dev/images/icons/warning.png)

## Gotchas

### 1\. Sources disagree about output quotes

The documentation page's examples and the original pull request show single-quoted output, matching the npm package. The type declaration's own example writes `{a:1,b:"two"}` with double quotes. If another program parses your output, parse it, not its quote style, and test the exact Bun version you ship on.

### 2\. Older Bun lacks the feature

The feature shipped in v1.3.7, so a CI image pinned to an earlier release has no `Bun.JSON5`. Check `bun --version` in CI, not just on your laptop.

### 3\. `NaN` and `Infinity` survive

Both functions accept and emit them, which `JSON.stringify` does not. A value that goes through JSON5 and then through `JSON.stringify` becomes `null`.

### 4\. Imports are frozen at build time

Bundled output holds the parsed object. Operators cannot edit the file in production and see a change. Read it at run time if they must.

### 5\. No streaming and no comments on output

The API is whole-string in, whole-string out, and comments are not preserved. For large inputs see [the performance tutorial](https://json5.dev/tutorials/performance/), and for untrusted input [the security tutorial](https://json5.dev/tutorials/security/).

### 6\. `package.json` is still JSON

Support for a `.json5` import does not change what Bun reads for its own manifest. A feature request for a `package.json5` file exists in the Bun repository (issue #26552); we did not verify its status, so keep `package.json` as plain JSON.

## JSON5 in Bun: Common Questions

### Which Bun version added JSON5?

Bun v1.3.7, released January 27, 2026. Bun 1.4 (August 20, 2026) later rewrote the runtime in Rust.

### Do I still need the `json5` npm package?

Not for plain parsing, writing and importing on Bun. Yes for a reviver, a replacer, the `quote` option, parse error line numbers, or code that must also run on Node.js or Deno.

### Is Bun's parser conformant?

Bun states that it passes 100% of the official test suite. See [what the suite checks](https://json5.dev/conformance/) and decide how much weight that statement carries for your files.

### Does Bun support JSONC or YAML too?

Its documentation places JSON5 beside JSON, TOML and YAML as first-class formats, and a `.jsonc` declaration appears in the type package. For how JSON5 compares, see [JSONC](https://json5.dev/compare/jsonc/) and [YAML](https://json5.dev/compare/yaml/).

### What does a bad file throw?

A `SyntaxError`. Wrap runtime parses in `try`/`catch`; an import of a broken file fails when the module is loaded.

## Related Pages

[![Deno logo](https://json5.dev/images/tech/deno.svg)

#### Deno

The other runtime, and what it lacks

](https://json5.dev/tools/deno/)[![Node.js logo](https://json5.dev/images/tech/nodejs.png)

#### Node.js Guide

The package and the require hook

](https://json5.dev/nodejs/)[![JavaScript logo](https://json5.dev/images/tech/javascript.png)

#### JavaScript Guide

The reference API

](https://json5.dev/javascript/)

## Sources

(11)

1.  [Bun documentation: JSON5](https://bun.com/docs/runtime/json5) (page header: Bun v1.4.5)
2.  [Bun guide: Import a JSON5 file](https://bun.com/guides/runtime/import-json5)
3.  [Bun v1.3.7 release notes, January 27, 2026](https://bun.com/blog/bun-v1.3.7)
4.  [Bun blog index (release dates; Bun 1.4 Rust rewrite)](https://bun.com/blog)
5.  [oven-sh/bun pull request 26439: native JSON5 parser](https://github.com/oven-sh/bun/pull/26439)
6.  [oven-sh/bun issue 3175: Implement JSON5 support as a module](https://github.com/oven-sh/bun/issues/3175)
7.  [oven-sh/bun pull request 46747: reviver and replacer (closed, not merged)](https://github.com/oven-sh/bun/pull/46747)
8.  [bun-types 1.4.5 on npm (bun.d.ts, extensions.d.ts, import-attributes.d.ts)](https://www.npmjs.com/package/bun-types)
9.  [json5/json5-tests: the official JSON5 test suite](https://github.com/json5/json5-tests)
10.  [Bun documentation: file types and loaders](https://bun.com/docs/runtime/file-types)
11.  [The JSON5 specification](https://json5.org/)

Last reviewed: November 29, 2026.
