JSON5 related APIs
namespace
JSON5
namespace JSON5
- input: string): unknown;
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.
@param inputThe JSON5 string to parse
@returnsA 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, }`); - input: unknown,replacer?: null,space?: string | number): undefined | string;
Convert a JavaScript value into a JSON5 string. Object keys that are valid identifiers are unquoted, strings use double quotes,
InfinityandNaNare represented as literals, and indented output includes trailing commas.@param inputThe JavaScript value to stringify.
@param replacerCurrently not supported.
@param spaceA 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.
@returnsA JSON5 string, or
undefinedif the input isundefined, 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, // }