jsonfix-llm 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,5 @@
1
+ from jsonfix_llm.extract.extract_code import extract_code
2
+ from jsonfix_llm.extract.extract_json import extract_json
3
+ from jsonfix_llm.repair.pipeline import repair_json
4
+
5
+ __all__ = ["repair_json", "extract_json", "extract_code"]
File without changes
@@ -0,0 +1,75 @@
1
+ import sys
2
+
3
+ import typer
4
+ from typer.core import TyperGroup
5
+
6
+ from jsonfix_llm import extract_code, repair_json
7
+
8
+
9
+ class NaturalOrderGroup(TyperGroup):
10
+ def parse_args(self, ctx, args):
11
+ if args and args[0] in self.commands:
12
+ return super().parse_args(ctx, args)
13
+ return super().parse_args(ctx, ["repair", *args])
14
+
15
+
16
+ app = typer.Typer(cls=NaturalOrderGroup)
17
+
18
+
19
+ @app.command()
20
+ def repair(
21
+ file: str = typer.Argument(None, help="JSON file to repair (stdin if omitted)"),
22
+ output: str = typer.Option(None, "-o", "--output", help="Write output to file"),
23
+ stats: bool = typer.Option(False, "--stats", help="Show repair statistics"),
24
+ ):
25
+ if file:
26
+ with open(file, encoding="utf-8") as f:
27
+ text = f.read()
28
+ else:
29
+ text = sys.stdin.read()
30
+
31
+ result = repair_json(text, rich=stats)
32
+ if stats:
33
+ typer.echo(result.fixed)
34
+ typer.echo(f"// Repaired: {result.was_repaired}", err=True)
35
+ fixes_summary = ", ".join(result.fixes) if result.fixes else "none"
36
+ typer.echo(f"// Fixes applied: {fixes_summary}", err=True)
37
+ typer.echo(f"// Errors: {result.error_count}", err=True)
38
+ if result.errors:
39
+ for err in result.errors:
40
+ typer.echo(f"// - {err}", err=True)
41
+ else:
42
+ output_text = result if isinstance(result, str) else result.fixed
43
+ if output:
44
+ with open(output, "w", encoding="utf-8") as f:
45
+ f.write(output_text)
46
+ else:
47
+ typer.echo(output_text)
48
+
49
+
50
+ @app.command()
51
+ def extract(
52
+ file: str = typer.Argument(None, help="File to extract from (stdin if omitted)"),
53
+ language: str = typer.Option("python", "--language", "-l",
54
+ help="Programming language to extract"),
55
+ output: str = typer.Option(None, "-o", "--output", help="Write output to file"),
56
+ all_blocks: bool = typer.Option(False, "--all", help="Extract all matching blocks"),
57
+ ):
58
+ if file:
59
+ with open(file, encoding="utf-8") as f:
60
+ text = f.read()
61
+ else:
62
+ text = sys.stdin.read()
63
+
64
+ result = extract_code(text, language=language, all=all_blocks)
65
+ output_text = "\n---\n".join(result) if isinstance(result, list) else result
66
+
67
+ if output:
68
+ with open(output, "w", encoding="utf-8") as f:
69
+ f.write(output_text)
70
+ else:
71
+ typer.echo(output_text)
72
+
73
+
74
+ if __name__ == "__main__": # pragma: no cover
75
+ app()
File without changes
@@ -0,0 +1,48 @@
1
+ import re
2
+
3
+
4
+ def _extract_fenced(text: str, language: str | None) -> list[str]:
5
+ if language:
6
+ lang_pattern = re.escape(language)
7
+ pattern = rf"```{lang_pattern}\s*\n(.*?)\n```"
8
+ else:
9
+ pattern = r"```\w*\s*\n(.*?)\n```"
10
+ return re.findall(pattern, text, re.DOTALL)
11
+
12
+
13
+ def _extract_xml(text: str, tag: str) -> list[str]:
14
+ pattern = rf"<{tag}>(.*?)</{tag}>"
15
+ return re.findall(pattern, text, re.DOTALL)
16
+
17
+
18
+ def _extract_indented(text: str) -> list[str]:
19
+ blocks = []
20
+ current: list[str] = []
21
+ for line in text.split("\n"):
22
+ if line.startswith(" ") or line.startswith("\t"):
23
+ current.append(line.lstrip())
24
+ elif current:
25
+ blocks.append("\n".join(current))
26
+ current = []
27
+ if current:
28
+ blocks.append("\n".join(current))
29
+ return blocks
30
+
31
+
32
+ def _extract_inline(text: str) -> list[str]:
33
+ return re.findall(r"`([^`]+)`", text)
34
+
35
+
36
+ def extract_code(text: str, language: str | None = None, all: bool = False) -> str | list[str]:
37
+ blocks = _extract_fenced(text, language)
38
+ if not blocks:
39
+ blocks = _extract_xml(text, "code")
40
+ if not blocks:
41
+ blocks = _extract_xml(text, "pre")
42
+ if not blocks:
43
+ blocks = _extract_indented(text)
44
+ if not blocks:
45
+ blocks = _extract_inline(text)
46
+ if all:
47
+ return blocks
48
+ return blocks[0] if blocks else text
@@ -0,0 +1,89 @@
1
+
2
+
3
+ def extract_json(text: str) -> str:
4
+ brace_depth = 0
5
+ bracket_depth = 0
6
+ in_string = False
7
+ escape = False
8
+ json_start = -1
9
+ json_end = -1
10
+
11
+ for i, char in enumerate(text):
12
+ if escape:
13
+ escape = False
14
+ continue
15
+ if char == "\\":
16
+ escape = True
17
+ continue
18
+ if char == '"':
19
+ in_string = not in_string
20
+ continue
21
+ if in_string:
22
+ continue
23
+
24
+ if char == "{":
25
+ if brace_depth == 0 and bracket_depth == 0:
26
+ json_start = i
27
+ brace_depth += 1
28
+ elif char == "}":
29
+ brace_depth -= 1
30
+ if brace_depth == 0 and bracket_depth == 0:
31
+ json_end = i + 1
32
+ break
33
+ elif char == "[":
34
+ if bracket_depth == 0 and brace_depth == 0:
35
+ json_start = i
36
+ bracket_depth += 1
37
+ elif char == "]":
38
+ bracket_depth -= 1
39
+ if bracket_depth == 0 and brace_depth == 0:
40
+ json_end = i + 1
41
+ break
42
+
43
+ if json_start >= 0 and json_end > json_start:
44
+ return text[json_start:json_end]
45
+
46
+ return text
47
+
48
+
49
+ def extract_json_all(text: str) -> list[str]:
50
+ blocks = []
51
+ in_string = False
52
+ escape = False
53
+ brace_depth = 0
54
+ bracket_depth = 0
55
+ start = -1
56
+
57
+ for i, char in enumerate(text):
58
+ if escape:
59
+ escape = False
60
+ continue
61
+ if char == "\\":
62
+ escape = True
63
+ continue
64
+ if char == '"':
65
+ in_string = not in_string
66
+ continue
67
+ if in_string:
68
+ continue
69
+
70
+ if char == "{":
71
+ if brace_depth == 0 and bracket_depth == 0:
72
+ start = i
73
+ brace_depth += 1
74
+ elif char == "}":
75
+ brace_depth -= 1
76
+ if brace_depth == 0 and bracket_depth == 0 and start >= 0:
77
+ blocks.append(text[start : i + 1])
78
+ start = -1
79
+ elif char == "[":
80
+ if bracket_depth == 0 and brace_depth == 0:
81
+ start = i
82
+ bracket_depth += 1
83
+ elif char == "]":
84
+ bracket_depth -= 1
85
+ if bracket_depth == 0 and brace_depth == 0 and start >= 0:
86
+ blocks.append(text[start : i + 1])
87
+ start = -1
88
+
89
+ return blocks
jsonfix_llm/models.py ADDED
@@ -0,0 +1,9 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class RepairResult(BaseModel):
5
+ fixed: str
6
+ was_repaired: bool
7
+ fixes: list[str] = []
8
+ error_count: int = 0
9
+ errors: list[str] = []
File without changes
@@ -0,0 +1,33 @@
1
+ def auto_close_brackets(text: str) -> str:
2
+ in_string = False
3
+ escape = False
4
+ stack = []
5
+
6
+ for char in text:
7
+ if escape:
8
+ escape = False
9
+ continue
10
+ if char == "\\":
11
+ escape = True
12
+ continue
13
+ if char == '"':
14
+ in_string = not in_string
15
+ continue
16
+ if in_string:
17
+ continue
18
+
19
+ if char == "{":
20
+ stack.append("}")
21
+ elif char == "[":
22
+ stack.append("]")
23
+ elif char == "}":
24
+ if stack and stack[-1] == "}":
25
+ stack.pop()
26
+ elif char == "]":
27
+ if stack and stack[-1] == "]":
28
+ stack.pop()
29
+
30
+ while stack:
31
+ text += stack.pop()
32
+
33
+ return text
@@ -0,0 +1,35 @@
1
+ import re
2
+
3
+
4
+ def fix_missing_commas(text: str) -> str:
5
+ text = re.sub(
6
+ r'("\s*)\n(\s*)("(?=[^:]*:))',
7
+ r"\1,\n\2\3",
8
+ text,
9
+ )
10
+ text = re.sub(r"(\})\s*\n(\s*)(\{)", r"\1,\n\2\3", text)
11
+ text = re.sub(r'(\])\s*\n(\s*)("(?=[^:]*:))', r"\1,\n\2\3", text)
12
+ text = re.sub(r'("\s*)\n(\s*)(\{)', r"\1,\n\2\3", text)
13
+ text = re.sub(r"(\})\s*\n(\s*)(\[)", r"\1,\n\2\3", text)
14
+ text = re.sub(r"(\])\s*\n(\s*)(\{)", r"\1,\n\2\3", text)
15
+ text = re.sub(r'(\])\s*\n(\s*)(\[)', r"\1,\n\2\3", text)
16
+ text = re.sub(
17
+ r"(\d+|true|false|null)\s*\n(\s*)("
18
+ r'"(?=[^:]*:))',
19
+ r"\1,\n\2\3",
20
+ text,
21
+ flags=re.IGNORECASE,
22
+ )
23
+ return text
24
+
25
+
26
+ def fix_trailing_commas(text: str) -> str:
27
+ text = re.sub(r",\s*\}", "}", text)
28
+ text = re.sub(r",\s*\]", "]", text)
29
+ return text
30
+
31
+
32
+ def fix_commas(text: str) -> str:
33
+ text = fix_trailing_commas(text)
34
+ text = fix_missing_commas(text)
35
+ return text
@@ -0,0 +1,50 @@
1
+ import re
2
+
3
+
4
+ def _is_inside_string(line: str, pos: int) -> bool:
5
+ in_double = False
6
+ in_single = False
7
+ escape = False
8
+ for i in range(pos):
9
+ ch = line[i]
10
+ if escape:
11
+ escape = False
12
+ continue
13
+ if ch == "\\":
14
+ escape = True
15
+ continue
16
+ if ch == '"' and not in_single:
17
+ in_double = not in_double
18
+ elif ch == "'" and not in_double:
19
+ in_single = not in_single
20
+ return in_double or in_single
21
+
22
+
23
+ def strip_line_comments(text: str) -> str:
24
+ lines = text.split("\n")
25
+ result = []
26
+ for line in lines:
27
+ comment_pos = -1
28
+ i = 0
29
+ while i < len(line):
30
+ if line[i] == "/" and i + 1 < len(line) and line[i + 1] == "/":
31
+ if not _is_inside_string(line, i):
32
+ comment_pos = i
33
+ break
34
+ i += 2
35
+ else:
36
+ i += 1
37
+ if comment_pos >= 0:
38
+ line = line[:comment_pos].rstrip()
39
+ result.append(line)
40
+ return "\n".join(result)
41
+
42
+
43
+ def strip_block_comments(text: str) -> str:
44
+ return re.sub(r"/\*[\s\S]*?\*/", "", text)
45
+
46
+
47
+ def strip_comments(text: str) -> str:
48
+ text = strip_block_comments(text)
49
+ text = strip_line_comments(text)
50
+ return text
@@ -0,0 +1,29 @@
1
+ def fix_control_chars(text: str) -> str:
2
+ result = []
3
+ in_string = False
4
+ escape = False
5
+ for char in text:
6
+ if escape:
7
+ result.append(char)
8
+ escape = False
9
+ continue
10
+ if char == "\\":
11
+ result.append(char)
12
+ escape = True
13
+ continue
14
+ if char == '"':
15
+ in_string = not in_string
16
+ result.append(char)
17
+ continue
18
+ if in_string:
19
+ if char == "\n":
20
+ result.append("\\n")
21
+ elif char == "\t":
22
+ result.append("\\t")
23
+ elif char == "\r":
24
+ result.append("\\r")
25
+ else:
26
+ result.append(char)
27
+ else:
28
+ result.append(char)
29
+ return "".join(result)
@@ -0,0 +1,45 @@
1
+ MAPPING = {
2
+ "True": "true",
3
+ "False": "false",
4
+ "None": "null",
5
+ "undefined": "null",
6
+ "NaN": "null",
7
+ }
8
+
9
+
10
+ def fix_python_literals(text: str) -> str:
11
+ result = []
12
+ in_string = False
13
+ escape = False
14
+ i = 0
15
+ while i < len(text):
16
+ ch = text[i]
17
+ if escape:
18
+ result.append(ch)
19
+ escape = False
20
+ i += 1
21
+ continue
22
+ if ch == "\\":
23
+ result.append(ch)
24
+ escape = True
25
+ i += 1
26
+ continue
27
+ if ch == '"':
28
+ in_string = not in_string
29
+ result.append(ch)
30
+ i += 1
31
+ continue
32
+ if in_string:
33
+ result.append(ch)
34
+ i += 1
35
+ continue
36
+ if ch.isalpha() or ch == "_":
37
+ start = i
38
+ while i < len(text) and (text[i].isalnum() or text[i] == "_"):
39
+ i += 1
40
+ word = text[start:i]
41
+ result.append(MAPPING.get(word, word))
42
+ else:
43
+ result.append(ch)
44
+ i += 1
45
+ return "".join(result)
@@ -0,0 +1,11 @@
1
+ def strip_markdown_fences(text: str) -> str:
2
+ lines = text.split("\n")
3
+ result = []
4
+ in_fence = False
5
+ for line in lines:
6
+ stripped = line.strip()
7
+ if stripped.startswith("```"):
8
+ in_fence = not in_fence
9
+ continue
10
+ result.append(line)
11
+ return "\n".join(result)
@@ -0,0 +1,77 @@
1
+ from jsonfix_llm.extract.extract_json import extract_json
2
+ from jsonfix_llm.models import RepairResult
3
+ from jsonfix_llm.repair.brackets import auto_close_brackets
4
+ from jsonfix_llm.repair.commas import fix_commas
5
+ from jsonfix_llm.repair.comments import strip_comments
6
+ from jsonfix_llm.repair.control_chars import fix_control_chars
7
+ from jsonfix_llm.repair.literals import fix_python_literals
8
+ from jsonfix_llm.repair.markdown import strip_markdown_fences
9
+ from jsonfix_llm.repair.quotes import fix_quotes
10
+ from jsonfix_llm.repair.values import fix_values
11
+ from jsonfix_llm.validators.validator import validate_json
12
+
13
+
14
+ def repair_json(text: str, rich: bool = False) -> str | RepairResult:
15
+ fixes = []
16
+
17
+ cleaned = strip_markdown_fences(text)
18
+ if cleaned != text:
19
+ fixes.append("markdown_fences_stripped")
20
+
21
+ if cleaned.startswith("\ufeff"):
22
+ cleaned = cleaned[1:]
23
+ fixes.append("bom_stripped")
24
+
25
+ no_comments = strip_comments(cleaned)
26
+ if no_comments != cleaned:
27
+ fixes.append("comments_stripped")
28
+ cleaned = no_comments
29
+
30
+ extracted = extract_json(cleaned)
31
+ if extracted != cleaned:
32
+ fixes.append("json_extracted")
33
+ cleaned = extracted
34
+
35
+ quoted = fix_quotes(cleaned)
36
+ if quoted != cleaned:
37
+ fixes.append("quotes_fixed")
38
+ cleaned = quoted
39
+
40
+ literals_fixed = fix_python_literals(cleaned)
41
+ if literals_fixed != cleaned:
42
+ fixes.append("literals_fixed")
43
+ cleaned = literals_fixed
44
+
45
+ commas_fixed = fix_commas(cleaned)
46
+ if commas_fixed != cleaned:
47
+ fixes.append("commas_fixed")
48
+ cleaned = commas_fixed
49
+
50
+ values_fixed = fix_values(cleaned)
51
+ if values_fixed != cleaned:
52
+ fixes.append("values_fixed")
53
+ cleaned = values_fixed
54
+
55
+ escaped = fix_control_chars(cleaned)
56
+ if escaped != cleaned:
57
+ fixes.append("control_chars_escaped")
58
+ cleaned = escaped
59
+
60
+ closed = auto_close_brackets(cleaned)
61
+ if closed != cleaned:
62
+ fixes.append("brackets_closed")
63
+ cleaned = closed
64
+
65
+ is_valid, errors = validate_json(cleaned)
66
+ was_repaired = len(fixes) > 0
67
+
68
+ if rich:
69
+ return RepairResult(
70
+ fixed=cleaned,
71
+ was_repaired=was_repaired,
72
+ fixes=fixes,
73
+ error_count=len(errors),
74
+ errors=errors,
75
+ )
76
+
77
+ return cleaned
@@ -0,0 +1,95 @@
1
+ def fix_single_quotes(text: str) -> str:
2
+ result = []
3
+ in_double = False
4
+ in_single = False
5
+ escape = False
6
+ for char in text:
7
+ if escape:
8
+ result.append(char)
9
+ escape = False
10
+ continue
11
+ if char == "\\":
12
+ result.append(char)
13
+ escape = True
14
+ continue
15
+ if char == '"' and not in_single:
16
+ in_double = not in_double
17
+ result.append(char)
18
+ elif char == "'" and not in_double:
19
+ in_single = not in_single
20
+ result.append('"')
21
+ else:
22
+ result.append(char)
23
+ return "".join(result)
24
+
25
+
26
+ def _find_identifier(text: str, start: int) -> tuple[int, int, str]:
27
+ i = start
28
+ while i < len(text) and text[i] in " \t\n\r":
29
+ i += 1
30
+ if i >= len(text) or not (text[i].isalpha() or text[i] == "_"):
31
+ return start, start, ""
32
+ ident_start = i
33
+ while i < len(text) and (text[i].isalnum() or text[i] == "_"):
34
+ i += 1
35
+ ident = text[ident_start:i]
36
+ j = i
37
+ while j < len(text) and text[j] in " \t\n\r":
38
+ j += 1
39
+ if j < len(text) and text[j] == ":":
40
+ return start, j + 1, ident
41
+ return start, start, ""
42
+
43
+
44
+ def fix_unquoted_keys(text: str) -> str:
45
+ result = []
46
+ in_double = False
47
+ in_single = False
48
+ escape = False
49
+ i = 0
50
+ while i < len(text):
51
+ ch = text[i]
52
+ if escape:
53
+ result.append(ch)
54
+ escape = False
55
+ i += 1
56
+ continue
57
+ if ch == "\\":
58
+ result.append(ch)
59
+ escape = True
60
+ i += 1
61
+ continue
62
+ if ch == '"':
63
+ in_double = not in_double
64
+ result.append(ch)
65
+ i += 1
66
+ continue
67
+ if ch == "'":
68
+ in_single = not in_single
69
+ result.append(ch)
70
+ i += 1
71
+ continue
72
+ if in_double or in_single:
73
+ result.append(ch)
74
+ i += 1
75
+ continue
76
+ if ch in ("{", ","):
77
+ result.append(ch)
78
+ i += 1
79
+ new_end, after_colon, ident = _find_identifier(text, i)
80
+ if ident:
81
+ result.append('"')
82
+ result.append(ident)
83
+ result.append('"')
84
+ result.append(":")
85
+ i = after_colon
86
+ continue
87
+ result.append(ch)
88
+ i += 1
89
+ return "".join(result)
90
+
91
+
92
+ def fix_quotes(text: str) -> str:
93
+ text = fix_single_quotes(text)
94
+ text = fix_unquoted_keys(text)
95
+ return text
@@ -0,0 +1,18 @@
1
+ import re
2
+
3
+
4
+ def fix_missing_values(text: str) -> str:
5
+ text = re.sub(r'(")\s*:\s*,', r"\1: null,", text)
6
+ text = re.sub(r'(")\s*:\s*\}', r"\1: null}", text)
7
+ return text
8
+
9
+
10
+ def fix_missing_colons(text: str) -> str:
11
+ text = re.sub(r'(")\s+("(?=[^:]*:))', r"\1: \2", text)
12
+ return text
13
+
14
+
15
+ def fix_values(text: str) -> str:
16
+ text = fix_missing_colons(text)
17
+ text = fix_missing_values(text)
18
+ return text
File without changes
@@ -0,0 +1,11 @@
1
+ import json
2
+
3
+
4
+ def validate_json(text: str) -> tuple[bool, list[str]]:
5
+ errors = []
6
+ try:
7
+ json.loads(text)
8
+ return True, errors
9
+ except json.JSONDecodeError as e:
10
+ errors.append(f"line {e.lineno}, col {e.colno}: {e.msg}")
11
+ return False, errors
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: jsonfix-llm
3
+ Version: 0.1.0
4
+ Summary: Repair broken JSON from LLM outputs
5
+ Author-email: shashi kundan <shashikundan0001@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/shashi3070/jsonfix-llm
8
+ Project-URL: Repository, https://github.com/shashi3070/jsonfix-llm
9
+ Project-URL: BugTracker, https://github.com/shashi3070/jsonfix-llm/issues
10
+ Keywords: json,llm,repair,fix,ai
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Text Processing :: General
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pydantic>=2.0
24
+ Requires-Dist: typer>=0.9
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4; extra == "dev"
28
+ Requires-Dist: ruff>=0.1; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # jsonfix-llm
32
+
33
+ Repair broken JSON from LLM outputs. Stop fighting malformed JSON.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install jsonfix-llm
39
+ ```
40
+
41
+ ## Quick Start
42
+
43
+ ```python
44
+ from jsonfix_llm import repair_json
45
+
46
+ fixed = repair_json("""{
47
+ 'name': 'shashi'
48
+ 'age': 25
49
+ }""")
50
+ # {"name": "shashi", "age": 25}
51
+ ```
52
+
53
+ ## Features
54
+
55
+ - **Markdown fence stripping** — removes ` ```json ... ``` ` wrappers
56
+ - **Comment stripping** — removes `//` and `/* */` comments
57
+ - **Quote fixing** — single quotes → double quotes, unquoted keys → quoted
58
+ - **Literal fixing** — `True/False/None` → `true/false/null`
59
+ - **Comma fixing** — inserts missing commas, removes trailing commas
60
+ - **Value fixing** — fills missing values, fixes missing colons
61
+ - **Control char escaping** — escapes literal newlines/tabs in strings
62
+ - **Bracket auto-close** — appends missing `}` or `]`, handles truncation
63
+ - **Code extraction** — extracts code from fenced, indented, inline, and XML blocks
64
+ - **CLI tool** — quick repair from the terminal
65
+
66
+ ## API
67
+
68
+ ```python
69
+ from jsonfix_llm import repair_json, extract_code, extract_json
70
+
71
+ # Simple repair
72
+ fixed = repair_json(text)
73
+
74
+ # Rich result
75
+ result = repair_json(text, rich=True)
76
+ print(result.fixed)
77
+ print(result.was_repaired)
78
+ print(result.fixes)
79
+ print(result.error_count)
80
+ print(result.errors)
81
+
82
+ # Extract code (default: first Python block)
83
+ code = extract_code(text)
84
+ # language-specific: extract_code(text, language="python")
85
+ # all blocks: extract_code(text, language="json", all=True)
86
+
87
+ # Extract JSON blocks
88
+ json_block = extract_json(text)
89
+ json_blocks = extract_json(text, all=True)
90
+ ```
91
+
92
+ ## CLI
93
+
94
+ ```bash
95
+ # Repair JSON file
96
+ jsonfix broken.json
97
+
98
+ # Read from stdin
99
+ echo '{"a":1' | jsonfix
100
+
101
+ # Write to file
102
+ jsonfix in.json -o fixed.json
103
+
104
+ # Show repair stats
105
+ jsonfix in.json --stats
106
+
107
+ # Extract code blocks
108
+ jsonfix extract file.md --language python
109
+ jsonfix extract file.md --language python -o output.py
110
+ jsonfix extract file.md --language json --all
111
+ ```
112
+
113
+ ## Development
114
+
115
+ ```bash
116
+ pip install -e ".[dev]"
117
+ pytest tests/ -v
118
+ ```
@@ -0,0 +1,25 @@
1
+ jsonfix_llm/__init__.py,sha256=8y4QbO4r7mhz9fYwggJtgkma05lRfex1Uq2uNjyqSgE,227
2
+ jsonfix_llm/models.py,sha256=WmBb_8MXQu4rc4G5Q8IXXFA6t5qqFQTBZWc0cQJzyqU,180
3
+ jsonfix_llm/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ jsonfix_llm/cli/main.py,sha256=0ugAbLDGws9mzFAR0HIYQap79AVWvG57S4HPGGOHsNs,2446
5
+ jsonfix_llm/extract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ jsonfix_llm/extract/extract_code.py,sha256=AJD2mr161WMQTjXf4UqNxyI_bosb_3ijGOVAqb_7IB0,1385
7
+ jsonfix_llm/extract/extract_json.py,sha256=UoWvlLLT55xf8XJC-lgdsZY00fl-I65JW7gwQT2z3XM,2357
8
+ jsonfix_llm/repair/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ jsonfix_llm/repair/brackets.py,sha256=YOM62wRzlDm_vpObthVj5OQYhTf3YbliGnYnvQX-5t8,755
10
+ jsonfix_llm/repair/commas.py,sha256=58hwa_t9PpvDJ8Q19Ln8_RG2YLkr2Vw3yzm24o1rFD4,969
11
+ jsonfix_llm/repair/comments.py,sha256=rZJ7xX4H8mFhw8xzfJjafhU6ujOB-EdsrKdKx8FH2K8,1293
12
+ jsonfix_llm/repair/control_chars.py,sha256=FjIZkLRIQdq0FwPWO0nQyoLRpK8LKP_-HTtNqFE22zQ,789
13
+ jsonfix_llm/repair/literals.py,sha256=dlA9j_fD1rbDAMwI2CstWogYVAcH5BZjdEMtGTHb__I,1067
14
+ jsonfix_llm/repair/markdown.py,sha256=P5NaXUXhIruLFEaPS_pZ_B3DN4JE3cZJ2a-zlJc3Q_Q,319
15
+ jsonfix_llm/repair/pipeline.py,sha256=OFnPcM4kYSSVhpygv8Huymcf9N-3g_g05nToxYkikZA,2308
16
+ jsonfix_llm/repair/quotes.py,sha256=QJFqsuiMGMv813Sx12cjcofBzuT18Hu0oOUSMQ65BWU,2537
17
+ jsonfix_llm/repair/values.py,sha256=uzyZTJJlJEVG4Jb4RlNd9rrHYhox7JdiNRLhw1xLJaM,422
18
+ jsonfix_llm/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ jsonfix_llm/validators/validator.py,sha256=87jFq5K62FYhiJn5YUFmTLkdLIWwANfGjQhOvsTGvL8,281
20
+ jsonfix_llm-0.1.0.dist-info/licenses/LICENSE,sha256=v2spsd7N1pKFFh2G8wGP_45iwe5S0DYiJzG4im8Rupc,1066
21
+ jsonfix_llm-0.1.0.dist-info/METADATA,sha256=hG5rF5ZZiske_dnhtjJ_vmPlWir1sNL1HeiyAhr9Ils,3326
22
+ jsonfix_llm-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
23
+ jsonfix_llm-0.1.0.dist-info/entry_points.txt,sha256=t5uti_8doLlMgaGNHT5kUkBpBloNzrK5TTVgTTEE-e4,53
24
+ jsonfix_llm-0.1.0.dist-info/top_level.txt,sha256=Tobbloae5p5SAtCD_4mRmSPERlmul52CQ4ZxHEZXd_s,12
25
+ jsonfix_llm-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ jsonfix = jsonfix_llm.cli.main:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ jsonfix_llm