A tool for extracting valid JSON from LLM responses
Project description
JsonExtractor
JsonExtractor
is a Python utility designed to extract valid JSON objects from strings. This is particularly useful for processing outputs from various sources where JSON objects may be embedded within larger text blobs.
Installation
To install JsonExtractor
, you can use pip:
pip install jsonextractor
Usage
After installation, JsonExtractor
can be imported and used in your Python projects to extract JSON objects from strings.
Example:
from json_extractor import JsonExtractor
# Some input string that contains a JSON object
input_string = 'Some text before JSON {"key": "value"} some text after JSON.'
# Extract the valid JSON object
valid_json = JsonExtractor.extract_valid_json(input_string)
if valid_json is not None:
print("Extracted JSON:", valid_json)
else:
print("No valid JSON found.")
Features
- Extracts the first valid JSON object found in a given string.
- Handles various formats, including JSON within markdown code blocks.
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
License
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
File details
Details for the file JsonExtractor-0.0.2.tar.gz
.
File metadata
- Download URL: JsonExtractor-0.0.2.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0a406d99fbb60684b55febf3e14dc012061f6b4bda549b010d5f7b0c3b6a8ea |
|
MD5 | b648156ed11d893a4c9b4525e1b42ba8 |
|
BLAKE2b-256 | de36bb6b1cc3f9cb10b0658102b22a5867527e677395d8fc697ae45db930d786 |
File details
Details for the file JsonExtractor-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: JsonExtractor-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c03712a5f62b85cfaaf5a16648452159e540ec52ccc959f328b7e2c198edac8 |
|
MD5 | df34bb9c261ac82d42d876b3ac58b97d |
|
BLAKE2b-256 | 251509238c0e0e3beabd27a1e3fb815b703773560c156e95de4ff752186f8b7e |