JSON5 related APIs
Search the reference...
/
namespace
Parse a JSON5 string into a JavaScript value.
JSON5 is a superset of JSON based on ECMAScript 5.1 that supports comments, trailing commas, unquoted keys, single-quoted strings, hex numbers, Infinity, NaN, and more.
The JSON5 string to parse
A JavaScript value
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,
}`);
Convert a JavaScript value into a JSON5 string. Object keys that are valid identifiers are unquoted, strings use double quotes, Infinity and NaN are represented as literals, and indented output includes trailing commas.
The JavaScript value to stringify.
Currently not supported.
A number for how many spaces each level of indentation gets, or a string used as indentation. The number is clamped between 0 and 10, and the first 10 characters of the string are used.
A JSON5 string, or undefined if the input is undefined, a function, or a symbol.
import { JSON5 } from "bun";
console.log(JSON5.stringify({ a: 1, b: "two" }));
// {a:1,b:"two"}
console.log(JSON5.stringify({ a: 1, b: 2 }, null, 2));
// {
// a: 1,
// b: 2,
// }
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →Bun.JSON5 object | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- JSON5 related APIs