json-repair 0.29.8__tar.gz → 0.29.10__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. {json_repair-0.29.8/src/json_repair.egg-info → json_repair-0.29.10}/PKG-INFO +1 -1
  2. {json_repair-0.29.8 → json_repair-0.29.10}/pyproject.toml +1 -1
  3. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair/json_parser.py +8 -5
  4. {json_repair-0.29.8 → json_repair-0.29.10/src/json_repair.egg-info}/PKG-INFO +1 -1
  5. {json_repair-0.29.8 → json_repair-0.29.10}/tests/test_json_repair.py +2 -0
  6. {json_repair-0.29.8 → json_repair-0.29.10}/LICENSE +0 -0
  7. {json_repair-0.29.8 → json_repair-0.29.10}/README.md +0 -0
  8. {json_repair-0.29.8 → json_repair-0.29.10}/setup.cfg +0 -0
  9. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair/__init__.py +0 -0
  10. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair/__main__.py +0 -0
  11. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair/json_context.py +0 -0
  12. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair/json_repair.py +0 -0
  13. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair/py.typed +0 -0
  14. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair/string_file_wrapper.py +0 -0
  15. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair.egg-info/SOURCES.txt +0 -0
  16. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair.egg-info/dependency_links.txt +0 -0
  17. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair.egg-info/entry_points.txt +0 -0
  18. {json_repair-0.29.8 → json_repair-0.29.10}/src/json_repair.egg-info/top_level.txt +0 -0
  19. {json_repair-0.29.8 → json_repair-0.29.10}/tests/test_coverage.py +0 -0
  20. {json_repair-0.29.8 → json_repair-0.29.10}/tests/test_performance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.8
3
+ Version: 0.29.10
4
4
  Summary: A package to repair broken json strings
5
5
  Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
6
6
  License: MIT License
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "json_repair"
6
- version = "0.29.8"
6
+ version = "0.29.10"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -83,7 +83,7 @@ class JSONParser:
83
83
  return self.parse_array()
84
84
  # there can be an edge case in which a key is empty and at the end of an object
85
85
  # like "key": }. We return an empty string here to close the object properly
86
- elif char == "}":
86
+ elif self.context.current == ContextValues.OBJECT_VALUE and char == "}":
87
87
  self.log(
88
88
  "At the end of an object we found a key with missing value, skipping",
89
89
  )
@@ -171,7 +171,8 @@ class JSONParser:
171
171
  arr = []
172
172
  self.context.set(ContextValues.ARRAY)
173
173
  # Stop when you either find the closing parentheses or you have iterated over the entire string
174
- while (self.get_char_at() or "]") != "]":
174
+ char = self.get_char_at()
175
+ while char and char not in ["]", "}"]:
175
176
  self.skip_whitespaces_at()
176
177
  value = self.parse_json()
177
178
 
@@ -317,12 +318,14 @@ class JSONParser:
317
318
  next_c = self.get_char_at(i)
318
319
  if next_c and next_c in [",", "}"]:
319
320
  rstring_delimiter_missing = False
320
- elif char == ",":
321
+ else:
322
+ # skip any whitespace first
323
+ i = self.skip_whitespaces_at(idx=1, move_main_index=False)
321
324
  # We couldn't find any rstring_delimeter before the end of the string
322
325
  # check if this is the last string of an object and therefore we can keep going
323
326
  # make an exception if this is the last char before the closing brace
324
- i = self.skip_to_character(character="}", idx=1)
325
- if i > 1:
327
+ j = self.skip_to_character(character="}", idx=i)
328
+ if j - i > 1:
326
329
  # Ok it's not right after the comma
327
330
  # Let's ignore
328
331
  rstring_delimiter_missing = False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.8
3
+ Version: 0.29.10
4
4
  Summary: A package to repair broken json strings
5
5
  Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
6
6
  License: MIT License
@@ -107,6 +107,7 @@ def test_missing_and_mixed_quotes():
107
107
  assert repair_json('{"" key":"val"') == '{" key": "val"}'
108
108
  assert repair_json('{"key": value "key2" : "value2" ') == '{"key": "value", "key2": "value2"}'
109
109
  assert repair_json('{"key": "lorem ipsum ... "sic " tamet. ...}') == '{"key": "lorem ipsum ... \\"sic \\" tamet. ..."}'
110
+ assert repair_json('{"key": value , }') == '{"key": "value"}'
110
111
 
111
112
  def test_array_edge_cases():
112
113
  assert repair_json("[1, 2, 3,") == "[1, 2, 3]"
@@ -144,6 +145,7 @@ def test_object_edge_cases():
144
145
  assert repair_json('{"lorem_ipsum": "sic tamet, quick brown fox. }') == '{"lorem_ipsum": "sic tamet, quick brown fox."}'
145
146
  assert repair_json('{"key":value, " key2":"value2" }') == '{"key": "value", " key2": "value2"}'
146
147
  assert repair_json('{"key":value "key2":"value2" }') == '{"key": "value", "key2": "value2"}'
148
+ assert repair_json("{'text': 'words{words in brackets}more words'}") == '{"text": "words{words in brackets}more words"}'
147
149
 
148
150
  def test_number_edge_cases():
149
151
  assert repair_json(' - { "test_key": ["test_value", "test_value2"] }') == '{"test_key": ["test_value", "test_value2"]}'
File without changes
File without changes
File without changes