A therapeutic JSON parser that gently massages malformed JSON into shape
Project description
jsonshiatsu 🤲
A therapeutic JSON parser for Python that gently massages malformed JSON back into shape. Like the Japanese healing art of shiatsu, this library applies just the right pressure points to transform broken JSON into something beautiful and usable.
Perfect for real-world scenarios where JSON may be improperly formatted, including LLM APIs, legacy systems, and user-generated content that can't be controlled. If you can control the model better use jsonformer. Regex is always an attack surface, be cautious when using this library.
Features
jsonshiatsu can heal JSON-like strings that would normally cause standard JSON parsing to fail, including:
- Unquoted object keys:
{test: "value"} - Single quotes:
{'test': 'value'} - Mixed quotes:
{"test": 'value'} - Trailing commas:
{"test": "value",} - Unquoted string values:
{test: value} - Embedded quotes with proper escaping
- Newlines in strings
- Markdown code blocks: Extract JSON from
```json ... ```blocks - Trailing explanatory text:
{"result": "success"} This indicates completion - JavaScript-style comments:
{"key": "value" /* comment */}and// line comments - Function call wrappers:
return {"data": [1, 2, 3]};orparse_json(...) - Multiple JSON objects: Extract the first valid JSON from multiple objects
- Non-standard boolean/null:
True/False,yes/no,None,undefined - Non-standard quotes: Smart quotes (
""), guillemets («»), CJK quotes (「」), backticks - Incomplete structures: Automatically close missing braces/brackets
Installation
Not yet submitted to pip.
pip install jsonshiatsu
Usage
Drop-in Replacement for json
The easiest way to use jsonshiatsu is as a direct replacement for Python's json module:
# Instead of: import json
import jsonshiatsu as json
# All standard json functionality works exactly the same
data = json.loads('{"name": "Alice", "age": 30}')
# But now malformed JSON also works!
data = json.loads('{ test: "this is a test"}') # Unquoted keys
data = json.loads("{'name': 'John', age: 30}") # Single quotes
data = json.loads('{"items": [1, 2, 3,]}') # Trailing commas
# File loading
with open('config.json') as f:
config = json.load(f)
# All json.loads parameters supported
from decimal import Decimal
data = json.loads('{"price": 123.45}', parse_float=Decimal)
Options
# Handle duplicate keys by creating arrays
result = jsonshiatsu.parse('{"key": "value1", "key": "value2"}', duplicate_keys=True)
print(result) # {'key': ['value1', 'value2']}
# Enable aggressive preprocessing for malformed JSON
result = jsonshiatsu.parse('return {"status": "ok"};', aggressive=True)
print(result) # {'status': 'ok'}
ParseLimits Class
You can limit the lenght, depth and count of the data.
Parameters:
max_input_size(int): Maximum input size in bytes (default: 10MB)max_string_length(int): Maximum string length (default: 1MB)max_number_length(int): Maximum number string length (default: 100)max_nesting_depth(int): Maximum nesting depth (default: 100)max_object_keys(int): Maximum keys per object (default: 10,000)max_array_items(int): Maximum items per array (default: 100,000)max_total_items(int): Maximum total parsed items (default: 1,000,000)
Examples
Real-world nightmares
llm_response = """```json
{
// Generated response
"response": {
"message": "Hello! I'd say "welcome" to you.",
'confidence': 0.95,
"timestamp": Date("2025-08-16T10:30:00Z"),
"metadata": {
model: gpt-4,
tokens: 150,
"categories": ["greeting", "polite",],
settings: {
temperature: 0.7,
'max_tokens': 1000
}
}
},
"status": "success", // Operation completed
debug_info: {
"processing_time": 1.23e-2,
"memory_usage": "45MB",
errors: [],
}
}
Limitations
- Some complex edge cases may not be handled perfectly
- Aggressive preprocessing mode should only be used with trusted inputs
- Performance can be much slower than regular json parsing. Use it only on malformed input.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsonshiatsu-0.2.1.tar.gz.
File metadata
- Download URL: jsonshiatsu-0.2.1.tar.gz
- Upload date:
- Size: 47.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9f4ff9910d01e277d40beb6c7a85bfdbfed8cb2b54f5dd08765351e17e12f76
|
|
| MD5 |
ca7190b474f1142079f232362dab7788
|
|
| BLAKE2b-256 |
2608e9d002436926a2e2e6924774b7317d98bd46732143092429a7a651823aab
|
File details
Details for the file jsonshiatsu-0.2.1-py3-none-any.whl.
File metadata
- Download URL: jsonshiatsu-0.2.1-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a278f52984515d223a03d3319cfcd4702efeceffd4dc2f20cdf29020b615a60d
|
|
| MD5 |
6b317930c0bcb5e851f3ae5d3745fc4b
|
|
| BLAKE2b-256 |
b6fec9a90f670984afcf33547f6d6a8d522171b7a7938a72a21ee837ad63ddd6
|