json-repair 0.55.1__py3-none-any.whl → 0.56.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.55.1
3
+ Version: 0.56.0
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-Expression: MIT
@@ -13,6 +13,9 @@ Classifier: Operating System :: OS Independent
13
13
  Requires-Python: >=3.10
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
+ Provides-Extra: schema
17
+ Requires-Dist: jsonschema>=4.21; extra == "schema"
18
+ Requires-Dist: pydantic>=2; extra == "schema"
16
19
  Dynamic: license-file
17
20
 
18
21
  [![PyPI](https://img.shields.io/pypi/v/json-repair)](https://pypi.org/project/json-repair/)
@@ -190,6 +193,58 @@ In strict mode the parser raises `ValueError` as soon as it encounters structura
190
193
 
191
194
  Strict mode still honors `skip_json_loads=True`; combining them lets you skip the initial `json.loads` check but still enforce strict parsing rules.
192
195
 
196
+ ### Schema-guided repairs
197
+
198
+ **Alpha feature (not yet in stable releases).** Schema-guided repairs are currently shipped only in alpha builds (e.g., `0.56.0-alpha.*`). The API and behavior may change or break between alpha releases.
199
+
200
+ You can guide repairs with a JSON Schema (or a Pydantic v2 model). When enabled, the parser will:
201
+
202
+ - Fill missing values (defaults, required fields).
203
+ - Coerce scalars where safe (e.g., `"1"` → `1` for integer fields).
204
+ - Drop properties/items that the schema disallows.
205
+
206
+ This is especially useful when you need deterministic, schema-valid outputs for downstream validation, storage, or typed processing. If the input cannot be repaired to satisfy the schema, `json_repair` raises `ValueError`.
207
+
208
+ Install the optional dependencies:
209
+
210
+ pip install 'json-repair[schema]'
211
+
212
+ (For CLI usage, you can also use `pipx install 'json-repair[schema]'`.)
213
+
214
+ Schema guidance is skipped for already-valid JSON unless you pass `skip_json_loads=True` (this forces the parser to run even on valid JSON). Schema guidance is mutually exclusive with `strict=True`.
215
+
216
+ ```
217
+ from json_repair import repair_json
218
+
219
+ schema = {
220
+ "type": "object",
221
+ "properties": {"value": {"type": "integer"}},
222
+ "required": ["value"],
223
+ }
224
+
225
+ repair_json('{"value": "1"}', schema=schema, skip_json_loads=True, return_objects=True)
226
+ ```
227
+
228
+ Pydantic v2 model example:
229
+
230
+ ```
231
+ from pydantic import BaseModel, Field
232
+ from json_repair import repair_json
233
+
234
+
235
+ class Payload(BaseModel):
236
+ value: int
237
+ tags: list[str] = Field(default_factory=list)
238
+
239
+
240
+ repair_json(
241
+ '{"value": "1", "tags": }',
242
+ schema=Payload,
243
+ skip_json_loads=True,
244
+ return_objects=True,
245
+ )
246
+ ```
247
+
193
248
  ### Use json_repair with streaming
194
249
 
195
250
  Sometimes you are streaming some data and want to repair the JSON coming from it. Normally this won't work but you can pass `stream_stable` to `repair_json()` or `loads()` to make it work:
@@ -207,7 +262,9 @@ pipx install json-repair
207
262
  to know all options available:
208
263
  ```
209
264
  $ json_repair -h
210
- usage: json_repair [-h] [-i] [-o TARGET] [--ensure_ascii] [--indent INDENT] [filename]
265
+ usage: json_repair [-h] [-i] [-o TARGET] [--ensure_ascii] [--indent INDENT]
266
+ [--skip-json-loads] [--schema SCHEMA] [--schema-model MODEL]
267
+ [--strict] [filename]
211
268
 
212
269
  Repair and parse JSON files.
213
270
 
@@ -221,6 +278,9 @@ options:
221
278
  If specified, the output will be written to TARGET filename instead of stdout
222
279
  --ensure_ascii Pass ensure_ascii=True to json.dumps()
223
280
  --indent INDENT Number of spaces for indentation (Default 2)
281
+ --skip-json-loads Skip initial json.loads validation (needed to force schema on valid JSON)
282
+ --schema SCHEMA Path to a JSON Schema file that guides repairs
283
+ --schema-model MODEL Pydantic v2 model in 'module:ClassName' form that guides repairs
224
284
  --strict Raise on duplicate keys, missing separators, empty keys/values, and similar structural issues instead of repairing them
225
285
  ```
226
286
 
@@ -274,8 +334,15 @@ If something is wrong (a missing parentheses or quotes for example) it will use
274
334
 
275
335
  I am sure some corner cases will be missing, if you have examples please open an issue or even better push a PR
276
336
 
337
+ # Contributing
338
+ If you want to contribute, start with `CONTRIBUTING.md` and read the Code Wiki writeup for a tour of the codebase and key entry points: https://codewiki.google/github.com/mangiucugna/json_repair
339
+
277
340
  # How to develop
278
- Just create a virtual environment with `requirements.txt`, the setup uses [pre-commit](https://pre-commit.com/) to make sure all tests are run.
341
+ Use `uv` to set up the dev environment and run tooling:
342
+
343
+ uv sync --group dev
344
+ uv run pre-commit run --all-files
345
+ uv run pytest
279
346
 
280
347
  Make sure that the Github Actions running after pushing a new commit don't fail as well.
281
348
 
@@ -0,0 +1,23 @@
1
+ json_repair/__init__.py,sha256=JQ4Nm8YzR8Id2a527Ql0Az-rKapTp8DCMPKybLtQ620,180
2
+ json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
3
+ json_repair/json_parser.py,sha256=IoS2HohE-qAMEDml960NT9L494wnkvTbWySmSSNp7bE,10503
4
+ json_repair/json_repair.py,sha256=mpzQi6ZfrZd8WqZX9aXIe-19LB8gTPtxy8QZRpDjT3o,16506
5
+ json_repair/parse_array.py,sha256=zuqE33NePib4c1U1RIrw0qlB0MNGMzCZVCXnUqPoNFA,4973
6
+ json_repair/parse_comment.py,sha256=ozOPPZBI1pyHxN98vTtmtMNNbdg4dOjvC06dkuXSzMs,2646
7
+ json_repair/parse_number.py,sha256=j-tYSnQbXOVENk4aJEeNY6wfAGUEjgLzQz5T5Nnvuj0,1296
8
+ json_repair/parse_object.py,sha256=Z89mqZ2Mm84OH_WZs61hxTNeJY9QXRcw6gZ6MrxeWqw,15224
9
+ json_repair/parse_string.py,sha256=Kq_u7Ya5ioctsOueQh1eY_fpXHWGLfW2193tJ7yesB4,26151
10
+ json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ json_repair/schema_repair.py,sha256=_mvpLs2xaiTdwZzJmV-FxzWVH6jdyPNuSYIU_ZufITo,22820
12
+ json_repair/parse_string_helpers/parse_boolean_or_null.py,sha256=pGmH1QATBls70kTvUlJv4F8NiPaBWcyGhRL03sTOnto,871
13
+ json_repair/parse_string_helpers/parse_json_llm_block.py,sha256=wPSm-8RY30Ek8HxzjCkCRtdLq4-Cez-PJB3vOk_vP3w,670
14
+ json_repair/utils/constants.py,sha256=MtvxHhcCq3jpgIThLUPjmH7nVeXSq6HjHDyQBntjVyY,378
15
+ json_repair/utils/json_context.py,sha256=WsMOjqpGSr6aaDONcrk8UFtTurzWon2Qq9AoBBYseoI,934
16
+ json_repair/utils/object_comparer.py,sha256=eKpIi9pMitZ3T_X1gIDlZv0-aPuvZqxSTphjIYD-8ys,1714
17
+ json_repair/utils/string_file_wrapper.py,sha256=dUYoSaMn1ahl72B1BfnNe0iqlV1wsxiZQK3gB0oHcyg,7054
18
+ json_repair-0.56.0.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
19
+ json_repair-0.56.0.dist-info/METADATA,sha256=8bHNoTqQJKzul8dPrbkA_NGJHQWkJ3NW0Qq2w03vcG8,14915
20
+ json_repair-0.56.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
21
+ json_repair-0.56.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
22
+ json_repair-0.56.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
23
+ json_repair-0.56.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.10.1)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,22 +0,0 @@
1
- json_repair/__init__.py,sha256=JQ4Nm8YzR8Id2a527Ql0Az-rKapTp8DCMPKybLtQ620,180
2
- json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
3
- json_repair/json_parser.py,sha256=1C24BNRNOg-hwJzLsCWuW75xYctm0haSynrDsGCy3d8,8595
4
- json_repair/json_repair.py,sha256=iT-OJgpBnKUJVIV4IUlXmMUkOyW6bNnKCZLB7Fys8hk,12758
5
- json_repair/parse_array.py,sha256=rZfnRiS86vBATOUHqSx2T5fE79Ndlk2NoTsg9Wek7l4,2239
6
- json_repair/parse_comment.py,sha256=MUDxrx8BFfAaKvx6x4gWviJNvwRi2yv5qnrR6honmas,2660
7
- json_repair/parse_number.py,sha256=zSsOZeJb-UTQkOrUSMsLKJJIJ0A9tGdwbQwQCWVOc4o,1314
8
- json_repair/parse_object.py,sha256=DH5xAqXIAM0hBhUUblfADuEs2JM8jnvd73h-KbFDcbQ,7859
9
- json_repair/parse_string.py,sha256=Dad1iQZDhF5MGAQ5eYs55O810yV1HCYPBkcHYH5AVBU,26275
10
- json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- json_repair/parse_string_helpers/parse_boolean_or_null.py,sha256=pGmH1QATBls70kTvUlJv4F8NiPaBWcyGhRL03sTOnto,871
12
- json_repair/parse_string_helpers/parse_json_llm_block.py,sha256=wPSm-8RY30Ek8HxzjCkCRtdLq4-Cez-PJB3vOk_vP3w,670
13
- json_repair/utils/constants.py,sha256=cv2gvyosuq0me0600WyTysM9avrtfXPuXYR26tawcuo,158
14
- json_repair/utils/json_context.py,sha256=WsMOjqpGSr6aaDONcrk8UFtTurzWon2Qq9AoBBYseoI,934
15
- json_repair/utils/object_comparer.py,sha256=XKV3MRab8H7_v4sm-wpEa5le0XX9OeycWo5S-MFm-GI,1716
16
- json_repair/utils/string_file_wrapper.py,sha256=jaS1vl_6qRQLJ-r37wZgMRtUJR6MLgNIGMVLqeGYBSk,6901
17
- json_repair-0.55.1.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
18
- json_repair-0.55.1.dist-info/METADATA,sha256=3usfVWz8_EMYrgdV3ZkPQ79NPvGYcA6Mpv9nhcjIuK8,12576
19
- json_repair-0.55.1.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
20
- json_repair-0.55.1.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
21
- json_repair-0.55.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
22
- json_repair-0.55.1.dist-info/RECORD,,