Comments (5)
Hi @michalkkkd I can't reproduce the issue.
When running the provided string like so:
print(repair_json('{"real_content": "Some string: Some other string Some string <a href=\\"https://domain.com\\">Some link</a>"}'))
It returns the correct json
When running it with the wrong escaping:
print(repair_json('{"real_content": "Some string: Some other string Some string <a href=\"https://domain.com\">Some link</a>"}'))
It returns a wrong dictionary but does not return a broken json.
I am running this on latest: 0.9.0
from json_repair.
Hi @mangiucugna :)
Github probably messed up when I pasted the snippet.
- I was albo to fix it temporarily using this replacement in PHP $data = str_replace('"', ''', $data);
- I updated the library (sorry, for not doing it earlier). Now I get this result:
So yes, json is not broken any more, but is unusable :(
from json_repair.
ok so this is an escaping issue and it's not trivial to address in general, I'll think about it but basically if you print that string, you can see that the escaping isn't passed to the function:
>>> print('{"real_content": "Some string: Some other string Some string <a href=\"https://domain.com\">Some link</a>"}')
{"real_content": "Some string: Some other string Some string <a href="https://domain.com">Some link</a>"}
Now, since it doesn't receive the escaping, there is no way for the library to handle the escaping and this is interpreted as a dictionary missing commas. The only (ugly) solution I can come up with is a regex for html tags that will escape those BUT it will break for cases in which the single comma is used like:
repair_json('{"real_content": \'Some string: Some other string Some string <a href="https://domain.com">Some link</a>\'}')
So need to give it more thoughts before I can deploy a fix for this type of breakage, a workaround is to use the following regex:
re.sub(r'(?<!\\\\)"', r'\\"', input_string)
That should fix the string (but again, I can't use that in json_repair because the escaping isn't passed over)
from json_repair.
I think, that your are extremely gifted to be able to create such an awesome string parsing library. Though I'm coding for years, low level string manipulation is an abstract concept for me.
Take your time!
from json_repair.
ok so I digged into this and the solution is still on your side, I will update the documentation for this problem but you should pass the string as a "raw string". Like:
json_string = r'{"real_content": "Some string: Some other string Some string <a href="https://domain.com\">Some link"}'
This will pass the escaping correctly and fix your issue, however I noticed that if the string was broken (i.e. missing last brace) the library would get confused. So I pushed a fix for that in 0.10.1
from json_repair.
Related Issues (20)
- Function "repair_json" raises an AttributeError exception when called with a certain input
- Special invalid json text: no response for a long time HOT 1
- Price like numbers not properly parsed HOT 2
- repair_json incorrectly truncates JSON strings with escaped quotes and commas HOT 3
- Parsing comments with float point number HOT 3
- [Bug]: Strings containing unescaped quotes followed by commas are incorrectly truncated HOT 2
- [Bug]: json_repair does not work for following json HOT 2
- [Bug]: HOT 2
- [Bug]: unescaped quotes immediately followed by comma fail. HOT 8
- [Bug]: poor repair from json to just integer HOT 6
- [Feature Request]: Get multiple valid fixes for an invalid JSON string HOT 2
- [Bug]: Fails to accurately capture value with missing opening quote if a comma comes before closing quote HOT 4
- [Bug]: Maximum recursion depth reached when parsing very long incompatible strings (2972 chars)
- [Bug]: Does not add missing comma in an array of strings but works fine with array of numbers HOT 1
- [Bug]: Failed repair on some quote cases HOT 1
- [Bug]: Unable to handle double quotes in start of string
- [Bug]: loading an ordinary string results in empty string object HOT 1
- [Bug]: Failing to parse truncated JSON (due to LLM repetition and max_tokens) HOT 1
- [Bug]: Extra backslash when repairing JSON with escaped double quote
- [Feature Request]: Add support for `mypy` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json_repair.