Skip to content

Commit

Permalink
Fixes #13. Release 0.7.0
Browse files Browse the repository at this point in the history
Sometimes json blocks are returned as markdown codeblocks, remove the backticks before processing the json
  • Loading branch information
mangiucugna committed Jan 27, 2024
1 parent 713b82f commit dea2790
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "json_repair"
version = "0.6.2"
version = "0.7.0"
license = {file = "LICENSE"}
authors = [
{ name="Stefano Baccianella", email="[email protected]" },
Expand Down
1 change: 1 addition & 0 deletions src/json_repair/json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def repair_json(
It will return the fixed string by default.
When `return_objects=True` is passed, it will return the decoded data structure instead.
"""
json_str = json_str.strip().lstrip("```json").rstrip("```")
parser = JSONParser(json_str)
if skip_json_loads:
parsed_json = parser.parse()
Expand Down
5 changes: 5 additions & 0 deletions tests/test_json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def test_repair_json():
assert repair_json('{ "content": "[LINK]("https://google.com")" }') == '{"content": "[LINK](\\"https://google.com\\")"}'
assert repair_json('{ "content": "[LINK](" }') == '{"content": "[LINK]("}'
assert repair_json('{ "content": "[LINK](", "key": true }') == '{"content": "[LINK](", "key": true}'
assert repair_json("""
```json
{ "key": "value" }
```""") == '{"key": "value"}'
assert repair_json('````{ "key": "value" }```') == '{"key": "value"}'



Expand Down
4 changes: 2 additions & 2 deletions tests/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def test_true_false_correct(benchmark):
mean_time = benchmark.stats.get("median")

# Define your time threshold in seconds
max_time = 21 * (1 / 10 ** 6) # 21 microsecond
max_time = 22 * (1 / 10 ** 6) # 21 microsecond

# Assert that the average time is below the threshold
assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
Expand Down Expand Up @@ -624,7 +624,7 @@ def test_false_false_correct(benchmark):
mean_time = benchmark.stats.get("median")

# Define your time threshold in seconds
max_time = 53 / 10 ** 6 # 53 microsecond
max_time = 54 / 10 ** 6 # 54 microsecond

# Assert that the average time is below the threshold
assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
Expand Down

0 comments on commit dea2790

Please sign in to comment.