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.7

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.7
File Size Uploaded
ld_json_extractor-0.1.7.tar.gz 2.3 kB Details

Built distribution (wheel)

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

Total release size: 5.3 kB

Release files / ld_json_extractor-0.1.7.tar.gz

Download URL ld_json_extractor-0.1.7.tar.gz
Size 2.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0f49f4f1d4429120cf4796f0c8d94fa35af566e3f0801e652430e098ef3e7a44
BLAKE2b-256 checksum
How to use checksums
7e7e85a721830ad9b87724e178378ca55dd7aab9921cce5a2b70cf5a13bf362f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.21

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

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

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

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