jsonld
This parser will interpret a JSON-LD document as an RDF Graph. See http://json-ld.org/
Example
>>> from rdflib import Graph, URIRef, Literal
>>> test_json = '''
... {
... "@context": {
... "dc": "http://purl.org/dc/terms/",
... "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
... "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
... },
... "@id": "http://example.org/about",
... "dc:title": {
... "@language": "en",
... "@value": "Someone's Homepage"
... }
... }
... '''
>>> g = Graph().parse(data=test_json, format='json-ld')
>>> list(g) == [(URIRef('http://example.org/about'),
... URIRef('http://purl.org/dc/terms/title'),
... Literal("Someone's Homepage", lang='en'))]
True
Classes:
Functions:
-
to_rdf–
JsonLDParser
Bases: Parser
Methods:
-
parse–Parse JSON-LD from a source document.
Source code in rdflib/plugins/parsers/jsonld.py
parse
parse(source: InputSource, sink: Graph, version: float = 1.1, skolemize: bool = False, encoding: Optional[str] = 'utf-8', base: Optional[str] = None, context: Optional[Union[List[Union[Dict[str, Any], str, None]], Dict[str, Any], str]] = None, generalized_rdf: Optional[bool] = False, extract_all_scripts: Optional[bool] = False, **kwargs: Any) -> None
Parse JSON-LD from a source document.
The source document can be JSON or HTML with embedded JSON script
elements (type attribute = application/ld+json). To process as HTML
source.content_type must be set to “text/html” or
`application/xhtml+xml.
Parameters:
-
(sourceInputSource) –InputSource with JSON-formatted data (JSON or HTML)
-
(sinkGraph) –Graph to receive the parsed triples
-
(versionfloat, default:1.1) –parse as JSON-LD version, defaults to 1.1
-
(skolemizebool, default:False) –whether to skolemize blank nodes, defaults to False
-
(encodingOptional[str], default:'utf-8') –character encoding of the JSON (should be “utf-8”
-
(baseOptional[str], default:None) –JSON-LD Base IRI, defaults to None
-
(contextOptional[Union[List[Union[Dict[str, Any], str, None]], Dict[str, Any], str]], default:None) –JSON-LD Context, defaults to None
-
(generalized_rdfOptional[bool], default:False) –parse as Generalized RDF, defaults to False
-
(extract_all_scriptsOptional[bool], default:False) –if source is an HTML document then extract script element). This is ignored if
source.system_idcontains a fragment identifier, in which case only the script element with matching id attribute is extracted.
Source code in rdflib/plugins/parsers/jsonld.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
Parser
Parser(generalized_rdf: bool = False, allow_lists_of_lists: Optional[bool] = None, skolemize: bool = False)
Methods:
-
parse–
Attributes:
-
allow_lists_of_lists– -
generalized_rdf– -
invalid_uri_to_bnode(dict[str, BNode]) – -
skolemize–
Source code in rdflib/plugins/parsers/jsonld.py
allow_lists_of_lists
instance-attribute
allow_lists_of_lists = allow_lists_of_lists if allow_lists_of_lists is not None else ALLOW_LISTS_OF_LISTS
parse
Source code in rdflib/plugins/parsers/jsonld.py
to_rdf
to_rdf(data: Any, dataset: Graph, base: Optional[str] = None, context_data: Optional[Union[List[Union[Dict[str, Any], str, None]], Dict[str, Any], str]] = None, version: Optional[float] = None, generalized_rdf: bool = False, allow_lists_of_lists: Optional[bool] = None, skolemize: bool = False)