json-repair 0.47.6__tar.gz → 0.47.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {json_repair-0.47.6/src/json_repair.egg-info → json_repair-0.47.7}/PKG-INFO +1 -1
  2. {json_repair-0.47.6 → json_repair-0.47.7}/pyproject.toml +1 -1
  3. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/json_parser.py +23 -12
  4. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/parse_array.py +6 -1
  5. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/parse_boolean_or_null.py +7 -1
  6. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/parse_comment.py +7 -1
  7. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/parse_number.py +7 -2
  8. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/parse_object.py +17 -7
  9. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/parse_string.py +6 -1
  10. {json_repair-0.47.6 → json_repair-0.47.7/src/json_repair.egg-info}/PKG-INFO +1 -1
  11. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_json_repair.py +1 -0
  12. {json_repair-0.47.6 → json_repair-0.47.7}/LICENSE +0 -0
  13. {json_repair-0.47.6 → json_repair-0.47.7}/README.md +0 -0
  14. {json_repair-0.47.6 → json_repair-0.47.7}/setup.cfg +0 -0
  15. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/__init__.py +0 -0
  16. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/__main__.py +0 -0
  17. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/constants.py +0 -0
  18. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/json_context.py +0 -0
  19. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/json_repair.py +0 -0
  20. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/object_comparer.py +0 -0
  21. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/py.typed +0 -0
  22. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair/string_file_wrapper.py +0 -0
  23. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair.egg-info/SOURCES.txt +0 -0
  24. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair.egg-info/dependency_links.txt +0 -0
  25. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair.egg-info/entry_points.txt +0 -0
  26. {json_repair-0.47.6 → json_repair-0.47.7}/src/json_repair.egg-info/top_level.txt +0 -0
  27. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_parse_array.py +0 -0
  28. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_parse_boolean_or_null.py +0 -0
  29. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_parse_comment.py +0 -0
  30. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_parse_number.py +0 -0
  31. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_parse_object.py +0 -0
  32. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_parse_string.py +0 -0
  33. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_performance.py +0 -0
  34. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_repair_json_cli.py +0 -0
  35. {json_repair-0.47.6 → json_repair-0.47.7}/tests/test_repair_json_from_file.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.47.6
3
+ Version: 0.47.7
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.47.6"
6
+ version = "0.47.7"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -3,23 +3,34 @@ from typing import Literal, TextIO
3
3
  from .constants import STRING_DELIMITERS, JSONReturnType
4
4
  from .json_context import JsonContext
5
5
  from .object_comparer import ObjectComparer
6
- from .parse_array import parse_array
7
- from .parse_boolean_or_null import parse_boolean_or_null
8
- from .parse_comment import parse_comment
9
- from .parse_number import parse_number
10
- from .parse_object import parse_object
11
- from .parse_string import parse_string
6
+ from .parse_array import parse_array as _parse_array
7
+ from .parse_boolean_or_null import parse_boolean_or_null as _parse_boolean_or_null
8
+ from .parse_comment import parse_comment as _parse_comment
9
+ from .parse_number import parse_number as _parse_number
10
+ from .parse_object import parse_object as _parse_object
11
+ from .parse_string import parse_string as _parse_string
12
12
  from .string_file_wrapper import StringFileWrapper
13
13
 
14
14
 
15
15
  class JSONParser:
16
16
  # Split the parse methods into separate files because this one was like 3000 lines
17
- parse_array = parse_array
18
- parse_boolean_or_null = parse_boolean_or_null
19
- parse_comment = parse_comment
20
- parse_number = parse_number
21
- parse_object = parse_object
22
- parse_string = parse_string
17
+ def parse_array(self, *args, **kwargs):
18
+ return _parse_array(self, *args, **kwargs)
19
+
20
+ def parse_boolean_or_null(self, *args, **kwargs):
21
+ return _parse_boolean_or_null(self, *args, **kwargs)
22
+
23
+ def parse_comment(self, *args, **kwargs):
24
+ return _parse_comment(self, *args, **kwargs)
25
+
26
+ def parse_number(self, *args, **kwargs):
27
+ return _parse_number(self, *args, **kwargs)
28
+
29
+ def parse_object(self, *args, **kwargs):
30
+ return _parse_object(self, *args, **kwargs)
31
+
32
+ def parse_string(self, *args, **kwargs):
33
+ return _parse_string(self, *args, **kwargs)
23
34
 
24
35
  def __init__(
25
36
  self,
@@ -1,8 +1,13 @@
1
+ from typing import TYPE_CHECKING
2
+
1
3
  from .constants import STRING_DELIMITERS, JSONReturnType
2
4
  from .json_context import ContextValues
3
5
 
6
+ if TYPE_CHECKING:
7
+ from .json_parser import JSONParser
8
+
4
9
 
5
- def parse_array(self) -> list[JSONReturnType]:
10
+ def parse_array(self: "JSONParser") -> list[JSONReturnType]:
6
11
  # <array> ::= '[' [ <json> *(', ' <json>) ] ']' ; A sequence of JSON values separated by commas
7
12
  arr = []
8
13
  self.context.set(ContextValues.ARRAY)
@@ -1,4 +1,10 @@
1
- def parse_boolean_or_null(self) -> bool | str | None:
1
+ from typing import TYPE_CHECKING
2
+
3
+ if TYPE_CHECKING:
4
+ from .json_parser import JSONParser
5
+
6
+
7
+ def parse_boolean_or_null(self: "JSONParser") -> bool | str | None:
2
8
  # <boolean> is one of the literal strings 'true', 'false', or 'null' (unquoted)
3
9
  starting_index = self.index
4
10
  char = (self.get_char_at() or "").lower()
@@ -1,7 +1,13 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from .constants import JSONReturnType
1
4
  from .json_context import ContextValues
2
5
 
6
+ if TYPE_CHECKING:
7
+ from .json_parser import JSONParser
8
+
3
9
 
4
- def parse_comment(self) -> str:
10
+ def parse_comment(self: "JSONParser") -> JSONReturnType:
5
11
  """
6
12
  Parse code-like comments:
7
13
 
@@ -1,10 +1,15 @@
1
- from .constants import JSONReturnType
1
+ from typing import TYPE_CHECKING
2
+
2
3
  from .json_context import ContextValues
3
4
 
4
5
  NUMBER_CHARS: set[str] = set("0123456789-.eE/,")
5
6
 
6
7
 
7
- def parse_number(self) -> float | int | str | JSONReturnType:
8
+ if TYPE_CHECKING:
9
+ from .json_parser import JSONParser
10
+
11
+
12
+ def parse_number(self: "JSONParser") -> float | int | str | bool | None:
8
13
  # <number> is a valid real number expressed in one of a number of given formats
9
14
  number_str = ""
10
15
  char = self.get_char_at()
@@ -1,8 +1,13 @@
1
+ from typing import TYPE_CHECKING
2
+
1
3
  from .constants import JSONReturnType
2
4
  from .json_context import ContextValues
3
5
 
6
+ if TYPE_CHECKING:
7
+ from .json_parser import JSONParser
8
+
4
9
 
5
- def parse_object(self) -> dict[str, JSONReturnType]:
10
+ def parse_object(self: "JSONParser") -> dict[str, JSONReturnType]:
6
11
  # <object> ::= '{' [ <member> *(', ' <member>) ] '}' ; A sequence of 'members'
7
12
  obj: dict[str, JSONReturnType] = {}
8
13
  # Stop when you either find the closing parentheses or you have iterated over the entire string
@@ -59,12 +64,17 @@ def parse_object(self) -> dict[str, JSONReturnType]:
59
64
  # If the string is empty but there is a object divider, we are done here
60
65
  break
61
66
  if ContextValues.ARRAY in self.context.context and key in obj:
62
- self.log(
63
- "While parsing an object we found a duplicate key, closing the object here and rolling back the index",
64
- )
65
- self.index = rollback_index - 1
66
- # add an opening curly brace to make this work
67
- self.json_str = self.json_str[: self.index + 1] + "{" + self.json_str[self.index + 1 :]
67
+ if self.stream_stable:
68
+ # This is possibly another problem, the key is incomplete and it "appears" duplicate
69
+ # Let's just do nothing
70
+ pass
71
+ else:
72
+ self.log(
73
+ "While parsing an object we found a duplicate key, closing the object here and rolling back the index",
74
+ )
75
+ self.index = rollback_index - 1
76
+ # add an opening curly brace to make this work
77
+ self.json_str = self.json_str[: self.index + 1] + "{" + self.json_str[self.index + 1 :]
68
78
  break
69
79
 
70
80
  # Skip filler whitespaces
@@ -1,8 +1,13 @@
1
+ from typing import TYPE_CHECKING
2
+
1
3
  from .constants import STRING_DELIMITERS
2
4
  from .json_context import ContextValues
3
5
 
6
+ if TYPE_CHECKING:
7
+ from .json_parser import JSONParser
8
+
4
9
 
5
- def parse_string(self) -> str | bool | None:
10
+ def parse_string(self: "JSONParser") -> str | bool | None:
6
11
  # <string> is a string of valid characters enclosed in quotes
7
12
  # i.e. { name: "John" }
8
13
  # Somehow all weird cases in an invalid JSON happen to be resolved in this function, so be careful here
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.47.6
3
+ Version: 0.47.7
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
@@ -158,3 +158,4 @@ def test_stream_stable():
158
158
  assert repair_json('{"key": "val\\n', stream_stable=True) == '{"key": "val\\n"}'
159
159
  assert repair_json('{"key": "val\\n123,`key2:value2', stream_stable=True) == '{"key": "val\\n123,`key2:value2"}'
160
160
  assert repair_json('{"key": "val\\n123,`key2:value2`"}', stream_stable=True) == '{"key": "val\\n123,`key2:value2`"}'
161
+ assert repair_json('[{"key": "value", "key', stream_stable=True) == '[{"key": "value"}]'
File without changes
File without changes
File without changes