Skip to content

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

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

embed instance-attribute

embed: Literal['@last', '@always', '@never', '@link']

Default @embed flag (default: @last).

expandContext instance-attribute

expandContext: Context

A context to expand with.

explicit instance-attribute

explicit: bool

Default @explicit flag (default: False).

extractAllScripts instance-attribute

extractAllScripts: bool

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

omitDefault instance-attribute

omitDefault: bool

Default @omitDefault flag (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).

pruneBlankNodeIdentifiers instance-attribute

pruneBlankNodeIdentifiers: bool

Remove unnecessary blank node identifiers (default: True).

requireAll instance-attribute

requireAll: bool

Default @requireAll flag (default: False).

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/"
}