Built for Ruby 3.1 and newer

JSON keeps its context.

Kochab parses JSONC, recovers from broken syntax, and changes only the bytes you intend. Comments and formatting stay where they belong.

  • Pure Ruby
  • Zero runtime dependencies
  • MIT licensed
settings.jsonc Valid with comments
{
  // Font size in points
  "editor": {
    "font_size": 14,
    "theme": "dark",
  },
}

Replace bytes 58…60. Every other byte remains untouched.

Work with the source, not around it.

Kochab keeps parsed values and their original representation connected through the entire edit.

Kochab.parse

Recover useful values

Consume the complete input and return structured diagnostics without throwing away the document around an error.

range_of · node_at

Locate exact syntax

Query UTF-8 byte ranges, syntax nodes, paths, comments, and zero-based UTF-16 positions for editor integrations.

set · insert · remove

Edit the smallest span

Generate validated text edits that preserve unrelated whitespace, comments, commas, and literal spelling.

Strict when you need it. Resilient when you do not.

Default parsing reports errors and returns the best available value. Strict mode accepts standard JSON only and raises with every diagnostic.

Explore parsing and recovery
doc = Kochab.parse(text)

doc.valid?            # false
doc.errors.first.code # :expected_colon
doc.value              # best available value

Add source-aware JSONC in one command.

Kochab has no runtime gem dependencies.

gem install kochab
View Kochab on RubyGems