Recursively expand and compact JSON-LD documents with caching and chained URL mappings
Project description
jsonld-recursive
Recursively expand and compact JSON-LD documents with caching and chained URL mappings.
Installation
npm install jsonld-recursive
Quick Start
CLI
# Standalone
ldr compact https://example.com/data.jsonld -d 3
# With server
ldr server start
ldr compact https://example.com/data.jsonld -d 3 --server
ldr server stop
Python
from lib.ldr_client import LdrClient
# Auto-start server
with LdrClient(auto_start_server=True) as client:
result = client.compact("https://example.com/data.jsonld", depth=3)
Browser (CDN)
<script src="https://cdn.jsdelivr.net/npm/jsonld-recursive@1/lib/ldr-core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jsonld-recursive@1/lib/ldr-browser.js"></script>
<script>
await JsonLdExpand.compact('https://example.com/data.jsonld', {depth: 3});
</script>
Server Commands
# Start
ldr server start
# Start with port
ldr server start 8080
# Start with mappings file
ldr server start 3000 mappings.json
# Start with JSON mappings
ldr server start 3000 '{"cmip7:*":"https://example.com/${rest}"}'
# Stop
ldr server stop
# Status
ldr server status
# Or kill by name
pkill ldr-server
Chained URL Mappings
Apply multiple mappings in sequence:
{
"cmip7:*": "https://wcrp-cmip.github.io/CMIP7-CVs/${rest}",
"https://wcrp-cmip.github.io/CMIP7-CVs/*": "/home/user/local-cvs/${rest}"
}
Input: cmip7:experiment/graph.jsonld
Step 1: cmip7:* → https://wcrp-cmip.github.io/CMIP7-CVs/experiment/graph.jsonld
Step 2: https://.../* → /home/user/local-cvs/experiment/graph.jsonld
Result: Loads from local file
Set Mappings
CLI:
# From file
ldr mappings set mappings.json
# From JSON (no -m flag needed)
ldr mappings set '{"cmip7:*":"https://example.com/${rest}"}'
# Get current
ldr mappings get
# Clear
ldr mappings clear
Python:
with LdrClient(auto_start_server=True) as client:
# Set chained mappings
client.set_mappings({
"cmip7:*": "https://wcrp-cmip.github.io/CMIP7-CVs/${rest}",
"https://wcrp-cmip.github.io/CMIP7-CVs/*": "/home/user/local-cvs/${rest}"
})
result = client.compact("cmip7:experiment/graph.jsonld", depth=3)
Python Client
Basic Usage
from lib.ldr_client import LdrClient
with LdrClient() as client:
result = client.compact("https://example.com/data.jsonld", depth=3)
Auto-start Server
# Server starts and stops automatically
with LdrClient(auto_start_server=True) as client:
result = client.compact("https://example.com/data.jsonld", depth=3)
Multiple Requests
with LdrClient(auto_start_server=True) as client:
urls = ["url1", "url2", "url3"]
# Loop
for url in urls:
result = client.compact(url, depth=3)
# Or batch
results = client.compact_batch(urls, depth=3)
Runtime Mappings
with LdrClient(auto_start_server=True) as client:
# Set mappings
client.set_mappings({
"cmip7:*": "https://wcrp-cmip.github.io/CMIP7-CVs/${rest}",
"https://wcrp-cmip.github.io/CMIP7-CVs/*": "/home/user/local/${rest}"
})
result = client.compact("cmip7:experiment/graph.jsonld", depth=3)
# Update
client.set_mappings({"new:*": "https://new.com/${rest}"})
# Clear
client.clear_mappings()
CLI Usage
# Standalone (no server)
ldr compact <url> -d 3
# With server (caching)
ldr compact <url> -d 3 --server
# Server management
ldr server start [port] [mappings.json]
ldr server stop
ldr server status
# Mappings (server must be running)
ldr mappings get
ldr mappings set mappings.json
ldr mappings set '{"prefix:*":"https://example.com/${rest}"}'
ldr mappings clear
Documentation
- docs/API.md - Full API reference
- docs/MAPPINGS.md - Detailed mappings guide
- example_script.py - Python example
Publishing
npm login
npm publish
After publishing, available via CDN:
https://cdn.jsdelivr.net/npm/jsonld-recursive@1/lib/ldr-core.jshttps://unpkg.com/jsonld-recursive@1/lib/ldr-core.js
License
MIT
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 jsonld_recursive-1.1.2.tar.gz.
File metadata
- Download URL: jsonld_recursive-1.1.2.tar.gz
- Upload date:
- Size: 3.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebd4877c334cb48b037ab8dd11c760df272a8eb646027767dcdcde16da7463e6
|
|
| MD5 |
cff8921425907ae68bf3f8d12f7c5e3f
|
|
| BLAKE2b-256 |
d2ee77dd5a3f5021e2793795c2b905299214a6452efee636921944e692fedfd5
|
Provenance
The following attestation bundles were made for jsonld_recursive-1.1.2.tar.gz:
Publisher:
publish2pypi.yml on wolfiex/jsonld-recursive
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonld_recursive-1.1.2.tar.gz -
Subject digest:
ebd4877c334cb48b037ab8dd11c760df272a8eb646027767dcdcde16da7463e6 - Sigstore transparency entry: 1283837254
- Sigstore integration time:
-
Permalink:
wolfiex/jsonld-recursive@e1e42f0271b38b3c243c0650a2cdaff658707352 -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/wolfiex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish2pypi.yml@e1e42f0271b38b3c243c0650a2cdaff658707352 -
Trigger Event:
push
-
Statement type:
File details
Details for the file jsonld_recursive-1.1.2-py3-none-any.whl.
File metadata
- Download URL: jsonld_recursive-1.1.2-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46d4761c84c7c945e5957e6fcc9a755b04ac8fceb51e8ce0f41018569b6484b2
|
|
| MD5 |
d364aee47c93f0b37552c013adaad072
|
|
| BLAKE2b-256 |
2f86127fcea57e6798665f0befbed65a0806a7ac9ae86dc30034f5b5bfd97013
|
Provenance
The following attestation bundles were made for jsonld_recursive-1.1.2-py3-none-any.whl:
Publisher:
publish2pypi.yml on wolfiex/jsonld-recursive
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonld_recursive-1.1.2-py3-none-any.whl -
Subject digest:
46d4761c84c7c945e5957e6fcc9a755b04ac8fceb51e8ce0f41018569b6484b2 - Sigstore transparency entry: 1283837299
- Sigstore integration time:
-
Permalink:
wolfiex/jsonld-recursive@e1e42f0271b38b3c243c0650a2cdaff658707352 -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/wolfiex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish2pypi.yml@e1e42f0271b38b3c243c0650a2cdaff658707352 -
Trigger Event:
push
-
Statement type: