JSON repair can solve multiple problems in json
Project description
Json Repair
The project is created from https://github.com/josdejong/jsonrepair project, which is a Javascript based solution for repairing bad or incomplete json data. It has been ported as python class.
The following issues can be fixed:
- Add missing quotes around keys
- Add missing escape characters
- Add missing commas
- Add missing closing brackets
- Repair truncated JSON
- Replace single quotes with double quotes
- Replace special quote characters like “...” with regular double quotes
- Replace special white space characters with regular spaces
- Replace Python constants None, True, and False with null, true, and false
- Strip trailing commas
- Strip comments like /* ... */ and // ...
- Strip ellipsis in arrays and objects like [1, 2, 3, ...]
- Strip JSONP notation like callback({ ... })
- Strip escape characters from an escaped string like {"stringified": "content"}
- Strip MongoDB data types like NumberLong(2) and ISODate("2012-12-19T06:01:17.171Z")
- Concatenate strings like "long text" + "more text on next line"
- Turn newline delimited JSON into a valid JSON array, for example:
{ "id": 1, "name": "John" }
{ "id": 2, "name": "Sarah" }
Usage:
from ssm_jsonrepair import JsonRepair
data = '[[{"$match":{"agent.name:{"$exists":1}}}]]'
jr = JsonRepair()
corrected = jr.jsonrepair(data)
print(corrected)
Error handling
In case of error there are 2 options:
- The program can correct the error => the corrected json is the result.
- The error cannot be repaired => JSONRepairError exception occurs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ssm_jsonrepair-3.8.1.tar.gz
(10.4 kB
view details)
Built Distribution
File details
Details for the file ssm_jsonrepair-3.8.1.tar.gz
.
File metadata
- Download URL: ssm_jsonrepair-3.8.1.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4d32af0cdee53e355512095139f1e8f34c14a5d87e6caffd698f74f33a79eba |
|
MD5 | ac237ec6641928e4d66b2075e1bd657b |
|
BLAKE2b-256 | 42a73f19f2518e4986af1d996b6ea6011a10da9f89d4149fa04347dd1b8262af |
File details
Details for the file ssm_jsonrepair-3.8.1-py3-none-any.whl
.
File metadata
- Download URL: ssm_jsonrepair-3.8.1-py3-none-any.whl
- Upload date:
- Size: 1.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 206e67b756a170df05b4184549d8f00ab3bbe18ffc529801760112f5efd4e3c8 |
|
MD5 | d8b79e680250699e04825eae2cb11c33 |
|
BLAKE2b-256 | b1392cda13a7113cf3b2ab97b80dc837eb3ba16fe92bc3e729b54ccd89ab0d12 |