jsonld.compact()¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
the JSON-LD input to compact. |
required | |
ctx
|
Context
|
the JSON-LD context to compact with. |
required |
options
|
CompactOptions | None
|
optional processing options; see Options below. |
None
|
Returns:
| Type | Description |
|---|---|
|
the compacted JSON-LD output. |
Options¶
compactArrays
instance-attribute
¶
True to compact arrays to single values when appropriate, False not to (default: True).
documentLoader
instance-attribute
¶
The document loader (default: the global default document loader).
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).
Example¶
Example compact.py
import json
from pyld import jsonld
doc = {
"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"
},
}
context = {
"name": "http://schema.org/name",
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
"image": {"@id": "http://schema.org/image", "@type": "@id"},
}
compacted = jsonld.compact(doc, context)
print(json.dumps(compacted, indent=2))