Skip to content

jsonld.expand()

Parameters:

Name Type Description Default
input_

the JSON-LD input to expand.

required
options ExpandOptions | None

optional processing options; see Options below.

None
on_property_dropped OnPropertyDropped

handler called on every ignored property.

noop

Returns:

Type Description

the expanded JSON-LD output.

Options

base instance-attribute

base: str

The base IRI to use.

documentLoader instance-attribute

documentLoader: DocumentLoader | DocumentLoaderCallable

The document loader (default: the global default document loader).

expandContext instance-attribute

expandContext: Context

A context to expand with.

extractAllScripts instance-attribute

extractAllScripts: bool

True to extract all JSON-LD script elements from HTML, False to extract just the first (default: False).

processingMode instance-attribute

processingMode: Literal['json-ld-1.0', 'json-ld-1.1']

Either json-ld-1.0 or json-ld-1.1 (default: json-ld-1.1).

Example

Example expand.py

import json

from pyld import jsonld

doc = {
    "@context": {
        "name": "http://schema.org/name",
        "homepage": {"@id": "http://schema.org/url", "@type": "@id"},
        "image": {"@id": "http://schema.org/image", "@type": "@id"},
    },
    "image": "http://manu.sporny.org/images/manu.png",
    "homepage": "http://manu.sporny.org/",
    "name": "Manu Sporny",
}

expanded = jsonld.expand(doc)

print(json.dumps(expanded, indent=2))
Output
[
  {
    "http://schema.org/url": [
      {
        "@id": "http://manu.sporny.org/"
      }
    ],
    "http://schema.org/image": [
      {
        "@id": "http://manu.sporny.org/images/manu.png"
      }
    ],
    "http://schema.org/name": [
      {
        "@value": "Manu Sporny"
      }
    ]
  }
]