Skip to main content

JSON repair can solve multiple problems in json

Project description

Jsonr 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 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


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.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

ssm_jsonrepair-3.8.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file ssm_jsonrepair-3.8.0.tar.gz.

File metadata

  • Download URL: ssm_jsonrepair-3.8.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.13

File hashes

Hashes for ssm_jsonrepair-3.8.0.tar.gz
Algorithm Hash digest
SHA256 0513cd4baf8e8c9dbc3d7b0338579d3dcee6499f3e64316e633d0e67c88a4381
MD5 31a3a75dd9a52afdf4ebfcf4ece4db5b
BLAKE2b-256 6411dd1be614aaf8fe1f98a9efab070d9f127724b51f051d2aae15dc216f0785

See more details on using hashes here.

File details

Details for the file ssm_jsonrepair-3.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ssm_jsonrepair-3.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b091cf0fb156aec21afc1e3cac6be98003f8bb273cb1d628db164d1daee56c69
MD5 86dda426d1e1daec6028ac9a1aa53093
BLAKE2b-256 97799b54f0b46dd5bba857ee012fa25818e1baaa494dd5cf049bfcbf46a86c18

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page