Kochab.parse
Recover useful values
Consume the complete input and return structured diagnostics without throwing away the document around an error.
Built for Ruby 3.1 and newer
Kochab parses JSONC, recovers from broken syntax, and changes only the bytes you intend. Comments and formatting stay where they belong.
{
// Font size in points
"editor": {
"font_size": 14,
"theme": "dark",
},
}
Replace bytes 58…60. Every other byte remains untouched.
Kochab keeps parsed values and their original representation connected through the entire edit.
Kochab.parse
Consume the complete input and return structured diagnostics without throwing away the document around an error.
range_of · node_at
Query UTF-8 byte ranges, syntax nodes, paths, comments, and zero-based UTF-16 positions for editor integrations.
set · insert · remove
Generate validated text edits that preserve unrelated whitespace, comments, commas, and literal spelling.
Default parsing reports errors and returns the best available value. Strict mode accepts standard JSON only and raises with every diagnostic.
Explore parsing and recoverydoc = Kochab.parse(text)
doc.valid? # false
doc.errors.first.code # :expected_colon
doc.value # best available value
Kochab has no runtime gem dependencies.
gem install kochab
View Kochab on RubyGems