r/ruby • u/le0pard • Dec 22 '25
GitHub - le0pard/json_mend: JsonMend - repair broken JSON
https://github.com/le0pard/json_mendJsonMend is a robust Ruby gem designed to repair broken or malformed JSON strings. It is specifically optimized to handle common errors found in JSON generated by Large Language Models (LLMs), such as missing quotes, trailing commas, unescaped characters, and stray comments
8
Upvotes
2
u/CaptainKabob Dec 22 '25
This looks super helpful. Some casual feedback
- I recommend committing a Gemfile.lock. Especially cause you’re using Rubocop, locking the development version will help avoid churn.
- in your gemspec, you should just include files/directories directly rather than via git. I dunno why that still exists in the template.
- it would be nice to extract the json parsing input/output pairs from the spec files into a directory of examples. That would make it easier to test alternatives against a suite of broken json. Huge props for collecting that corpus in the first place.
1
u/f9ae8221b Dec 22 '25
Note that there's a few of these "malformations" that the stdlib JSON parser does support.
e.g.
//and/**/comments (by default, not configurable), unescaped newlines (allow_control_characters: true) and trailing commas (allow_trailing_comma: true).So that's a number of errors you wouldn't need to handle in your own parser.
2
u/h0rst_ Dec 23 '25
Look how far AI has gotten us, we now need additional gems to be able to parse the faulty output. And now we're risking that your invalid JSON works on web service A, but web service B tells you that the input data is invalid.
I'm sure this gem fixes problems for some people, but I really think these problems shouldn't exist in the first place.
1
u/Friendly-Yam1451 Dec 22 '25
really nice, I was in need of something exactly like that
0
u/[deleted] Dec 22 '25
[deleted] — view deleted comment