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.
function
JSON5.stringify
input: unknown,
replacer?: null,
space?: string | number
): undefined | string;
@param input
The JavaScript value to stringify.
@param replacer
Currently not supported.
@param space
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.
@returns
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,
// }