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.1.tar.gz (3.6 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.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonquotefixer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 145fbc7ade2ee323a945456768816a6d46997a4412221f4769680b6acbbb8065
MD5 81fb56845b79928311a644f4f635fa2e
BLAKE2b-256 98bea725bf983cfd90f4317e476ee45f4355af5091d35d3ce12f0557d54700c2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonquotefixer-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49d4555ebd7c445118a0b756f90b132294b905185d9edf3bec562b766a2f7e9b
MD5 6a3c2b925bd66ab6a090f4833a6c4ae7
BLAKE2b-256 331cd816308dd75911ebbef4c2fa2132bc5a1cf03c9be2a3861032d6b9c8de7e

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