Skip to main content

ld_json_extractor

A lightweight Python library designed to extract ld+json from <script> tags within HTML documents

Installation

Using uv:

uv add ld_json_extractor

Quick Start

1. Extract JSON-LD Data from HTML

from selectolax.lexbor import LexborHTMLParser
from ld_json_extractor import json_iter

html_content = """
<!DOCTYPE html>
<html>
<head>
    <script type="application/ld+json">
        {"@context": "[https://schema.org](https://schema.org)", "@type": "Organization", "name": "Example Corp"}
    </script>
    <script type="application/ld+json">
        {"@type": "Product", "name": "Gaming Laptop", "price": 1200}
    </script>
</head>
</html>
"""

parser = LexborHTMLParser(html_content)

for data in json_iter(parser, script_type="application/ld+json"):
    print(data)
# Output:
# {'@context': '[https://schema.org](https://schema.org)', '@type': 'Organization', 'name': 'Example Corp'}
# {'@type': 'Product', 'name': 'Gaming Laptop', 'price': 1200}

2. Find Specific @type (Objects & Lists)

from selectolax.lexbor import LexborHTMLParser
from ld_json_extractor import find_ld_json

html_content = """
<script type="application/ld+json">
    [
        {"@type": "BreadcrumbList", "itemListElement": []},
        {"@type": "Product", "name": "Wireless Mouse", "price": 25}
    ]
</script>
"""

parser = LexborHTMLParser(html_content)

# Automatically searches inside both single JSON objects and array lists
product = find_ld_json("Product", parser)
print(product)
# Output:
# {'@type': 'Product', 'name': 'Wireless Mouse', 'price': 25}

Metadata

Release files for ld-json-extractor 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ld-json-extractor 0.1.6
File Size Uploaded
ld_json_extractor-0.1.6.tar.gz 2.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ld-json-extractor 0.1.6
File Interpreter ABI Platform
ld_json_extractor-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 5.4 kB

Release files / ld_json_extractor-0.1.6.tar.gz

Download URL ld_json_extractor-0.1.6.tar.gz
Size 2.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9e88c7bd8cbc027af06ea50262c1664717c8c1dcb76bd01c3c8c4250604a6b9c
BLAKE2b-256 checksum
How to use checksums
88be7e6ae0f780774164ddef77b2acf211272768f546a6c31abf07450c0769c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.21

Release files / ld_json_extractor-0.1.6-py3-none-any.whl

Download URL ld_json_extractor-0.1.6-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3264b2afc55e6610b435afb4b631c7316e1573f5f6b0c5df9561d5fcc604d189
BLAKE2b-256 checksum
How to use checksums
2066e882597f1fde7b54e08b41aa451c929d37826ce4542a372b1c80a1677709
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.21

Release history Release notifications | RSS feed

0.1.7

2 release files

This release

0.1.6 This release

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page