Skip to main content

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


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

Uploaded Source

Built Distribution

ssm_jsonrepair-3.8.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ssm_jsonrepair-3.8.2.tar.gz
Algorithm Hash digest
SHA256 fb87b93d001f19c42686047d2d6a8d550e770d41472fb2ec25553ca93cf9fd83
MD5 4740e9b4f39b36a34f91ba5484a2642a
BLAKE2b-256 af237fa0ff72300cec2103476f5133e3165a3422098f4fdf24508ec09cff6d5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_jsonrepair-3.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b00164293de52e47fcdaddeeb96b9178a632a1c0ce1f80367613a59a9157bdf
MD5 bfed709ce0464883b1a5cc5b35bbe107
BLAKE2b-256 7402eaa23a68d2245bd9f855687656d71ea6e19063cb6dc8ac913c1e499bdfde

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