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

Installation

pip install jsonquotefixer

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

Example

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.2.0.tar.gz (3.4 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.2.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonquotefixer-0.2.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for jsonquotefixer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cba7e954a51f4a15c1c4f66bfa84a87383d73b407d9a99fbccd8dc358f0c92e5
MD5 8571cb04e29eec5ea57a9754882f6af5
BLAKE2b-256 3c459a061959d9470d5eba6acbc6beeb2d78ba7612d3bf26fe4b4eddf599d687

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonquotefixer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for jsonquotefixer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3301bff41d0c8c0e9377d9b483f480c62391d6dbd23af4523d29bb205c08438
MD5 4577e1a4f50e27e810d0e5ee35aa2e39
BLAKE2b-256 d2479bc70f2513b7b920947281c9837296224073b4199fa540c9d749beeb8087

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