温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/JSON5
点击访问原文链接

Bun.JSON5 object | API Reference | Bun

Bun.JSON5 object | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/Bun/JSON5FparseFstringify

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/JSON5FparseFstringify

namespace

JSON5namespace JSON5

JSON5 related APIs

function parse(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 input

The JSON5 string to parse

@returns

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,
}`);
function stringify(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, Infinity and NaN are represented as literals, and indented output includes trailing commas.

@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,
// }

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Bun.JSON5 object | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    JSON5 related APIs