-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve repairing missing end quotes of strings containing delimiters like comma or single quote #102
Comments
Thanks for reporting, it would be nice to improve on this. The simplest logic to repair a missing quote is to add a missing quote at the end of the text. However, this can completely mess up a JSON document if only a single value somewhere at the beginning of a document is missing an end quote (see #97). Therefore, in case of a missing end quote, |
I was thinking about this. Right now, the logic checks for "any" delimiter to find the place where the end quote is missing. We can improve this by providing the internal function |
ran into an issue today where string values contained unescaped quotes, like so: "key": "apple "bee" carrot" rather than "key": "apple \"bee\" carrot" not sure if that's a similar issue with quote delimiters or completely opposite. thoughts? what sort of help would you like with this? |
That is a nice one. Right now, the library works locally: whilst parsing and encountering a missing delimiter like a comma or quote, it will repair the document locally. Your example probably requires looking at the document as a whole. I think in general, a document contains one type of error like missing quotes, a truncated document, or in your case having unescaped quotes in strings. To solve that for real, I think It would be interesting to think that through, though I don't think your case is trivial to solve. For example, how would one interpret the following case:
Is this one string containing 4 unescaped quotes? Or are these just three valid strings? Maybe this is just a hypothetical case though, in your example it is possible to see which quote is the "real" end quote from the context. |
great question. without knowing the author's intent impossible to be sure what they wanted, but if I consider "what is valid JSON?" then your sample is already valid and thus jsonrepair should not alter it. the example I gave does not parse, so needs repair of some kind… turning it into |
Yes indeed, if the JSON is already valid, we're done directly. When not, the library somehow needs to go through a couple of "most logical" scenarios to identify what is wrong an how to fix it, looking at the whole of the document. It will be interesting to that out 🤔. |
nice! :) thanks @josdejong! |
For example, in playground (https://josdejong.github.io/jsonrepair/) :
or
both fail.
(strings with comma or simple-quote, without ending double quote)
My personal fixes are the followings :
The text was updated successfully, but these errors were encountered: