parse

import { parse } from "jsr:@ende/jsonc";

function

function parse(text: string): JsonValue

Converts a JSON with Comments (JSONC) string into an object.

text: string

A valid JSONC string.

Returns

The parsed JsonValue from the JSONC string.

Example: Usage

import { parse } from "@ende/jsonc";
import { assertEquals } from "@ende/assert";

assertEquals(parse('{"foo": "bar"}'), { foo: "bar" });
assertEquals(parse('{"foo": "bar", }'), { foo: "bar" });
assertEquals(parse('{"foo": "bar", } /* comment *\/'), { foo: "bar" });

Source