Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Json5 unstable

Parses JSON5 configuration files without external dependencies.

The compatibility target is JSON5 1.0.0 and the value-parsing behavior of json5 2.2.3, without its optional reviver. Identifier names use the runtime's Unicode property tables.

1 exports Since v4.1.2 Source

Decoding

parse

unstable
Since v4.1.2

Parses a JSON5 document into a JavaScript value.

Details

Returns Result.succeed with the parsed value, or Result.fail with an EncodingError when the input is not valid JSON5. Accepts comments, trailing commas, unquoted identifier keys, single-quoted strings, hexadecimal numbers, Infinity, and NaN. Duplicate keys use the last value; __proto__ is preserved as an own data property.

Gotchas

Error messages give a line and column but do not include the input text. Unlike JSON.parse, this function has no reviver.

Signature

declare function parse(input: string): Result<unknown, EncodingError>

Example Parsing a JSON5 document

import { Result } from "effect"
import { Json5 } from "effect/encoding"
Json5.parse("{ port: 8080, }") // => Result.succeed({ port: 8080 })
Result.isFailure(Json5.parse("{ port: }")) // => true