Skip to main content

A tool for extracting valid JSON from LLM responses

Project description

PyPI version License: MIT Downloads

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

MIT

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

JsonExtractor-0.0.1.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

JsonExtractor-0.0.1-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

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