jsonld.frame()¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
the JSON-LD input to frame. |
required | |
frame
|
the JSON-LD frame to use. |
required | |
options
|
FrameOptions | None
|
optional processing options; see Options below. |
None
|
Returns:
| Type | Description |
|---|---|
|
the framed JSON-LD output. |
Options¶
documentLoader
instance-attribute
¶
The document loader (default: the global default document loader).
embed
instance-attribute
¶
Default @embed flag (default: @last).
extractAllScripts
instance-attribute
¶
True to extract all JSON-LD script elements from HTML, False to extract just the first (default: False).
processingMode
instance-attribute
¶
Either json-ld-1.0 or json-ld-1.1 (default: json-ld-1.1).
pruneBlankNodeIdentifiers
instance-attribute
¶
Remove unnecessary blank node identifiers (default: True).
Example¶
Example frame.py
import json
from pyld import jsonld
doc = {
"@id": "http://example.com/people/manu",
"@type": "http://schema.org/Person",
"http://schema.org/name": "Manu Sporny",
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
"http://schema.org/image": {
"@id": "http://manu.sporny.org/images/manu.png"
},
}
frame = {
"@context": {
"name": "http://schema.org/name",
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
"image": {"@id": "http://schema.org/image", "@type": "@id"},
},
"@type": "http://schema.org/Person",
}
framed = jsonld.frame(doc, frame)
print(json.dumps(framed, indent=2))
Output
{
"@context": {
"name": "http://schema.org/name",
"homepage": {
"@id": "http://schema.org/url",
"@type": "@id"
},
"image": {
"@id": "http://schema.org/image",
"@type": "@id"
}
},
"@id": "http://example.com/people/manu",
"@type": "http://schema.org/Person",
"image": "http://manu.sporny.org/images/manu.png",
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/"
}