Skip to main content

Fixer for broken/unescaped quotes in pseudo-JSON text

Project description

Json Fixer

Motivation

AI models often generate malformed JSON output due to incorrect handling of quotation marks.
A common issue is improperly nested double quotes, which makes the JSON invalid and unparseable with json.loads.
For example:

{
    "key1": "value1",
    "key2": "value2 is behind the "value1", that is good ",
}

The snippet above will raise a JSONDecodeError because of the invalid quoting.

Usage

jsonfixer automatically fixes broken quotation marks, allowing the JSON to be safely parsed with Python’s built-in json module.

Example usage:

import json
from jsonfixer import fix_quotes

a = <a malformed JSON-like string to be fixed>
json.loads(a)  # Raises JSONDecodeError!

b = fix_quotes(a)
json.loads(b)  # Successfully parsed

Arguments of fix_quotes

  • s: a malformed JSON-like string to be fixed
  • parse_code (bool, default=False): if True, extracts and fixes JSON from strings wrapped in triple backticks (```)
  • replace_smart (bool, default=False): if True, replaces smart quotes (“ ”) with escaped straight quote (")

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

jsonquotefixer-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonquotefixer-0.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file jsonquotefixer-0.1.1.tar.gz.

File metadata

  • Download URL: jsonquotefixer-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for jsonquotefixer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5f474e193253c242d0910aaddca85f58f27c3711ef4917f4d5d182326314649f
MD5 9469b94fbdf86be10372a8901b281151
BLAKE2b-256 b2ddc3c9cbbf428dc4297f50908a1641aeed5cf643cea926f532f8f01a5c0129

See more details on using hashes here.

File details

Details for the file jsonquotefixer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: jsonquotefixer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for jsonquotefixer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61fe93a9f2b3c7362946254d981bba09e6008f919f2b4743510bebfab19927a7
MD5 4c010d2577102c144f525fdde9b56457
BLAKE2b-256 7bd0d344eda567ab636c5dc53e4418799f46d7b55d7defa58ed0f022e6f1084b

See more details on using hashes here.

Supported by

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