jsonc-effect
v0.2.1
Published
Pure Effect-TS implementation of a JSONC (JSON with Comments) parser
Downloads
1,600
Maintainers
Readme
jsonc-effect
Pure Effect JSONC (JSON with Comments) parser with no external parser dependencies. Scanner, parser, AST, and formatting are all implemented natively.
Features
- Effect-native -- typed errors, Schema integration, and composable pipelines
- Zero parser dependencies --
effectis the sole runtime dependency - Schema integration -- parse JSONC strings directly into validated types
- Full toolchain -- scanner, parser, AST navigation, visitor stream, formatting, and modification
- Equality comparisons -- compare JSONC documents semantically, ignoring comments, formatting, and key ordering
- Safe by default -- returns
unknown(notany) andOption(notundefined)
Installation
npm install jsonc-effect effectQuick Start
import { parse } from "jsonc-effect"
import { Effect } from "effect"
const result = Effect.runSync(
parse('{ "key": 42, /* comment */ }')
)
// => { key: 42 }Semantically compare two JSONC documents:
import { equals } from "jsonc-effect"
import { Effect } from "effect"
// Semantically equal despite different formatting, comments, and key order
const same = Effect.runSync(
equals(
'{ "foo": 1, "bar": 2 }',
'{ "bar": 2, /* comment */ "foo": 1 }'
)
)
// => trueFAQ
Why does this module exist?
If you just need to parse JSONC into a JavaScript object, use jsonc-parser or Bun's native JSONC support. They are faster and have no dependencies.
This library is for Effect-based programs that need deeper introspection and editing of JSONC documents: typed parse errors you can catchTag, Schema pipelines that validate JSONC strings into domain types, AST navigation, document modification and SAX-style visitor streams that are composable in Effect pipelines.
Documentation
For API reference, advanced usage, and examples, see docs.
