Skip to content

JSON-LD serialization apparently loses XSD type information. #2812

@lu-pl

Description

@lu-pl

JSON-LD serialization apparently loses XSD type information.

from rdflib import Graph, Literal, URIRef, XSD


graph: Graph = Graph()
graph.add(
    (
        URIRef("https://test.subject"),
        URIRef("https://test.predicate"),
        Literal("test type", datatype=XSD.string),
    )
)

## 1. check literal type of constructed graph object
# pass
assert all(o.datatype for o in graph.objects())

## 2. check literal type of xml parsed graph object
xml_serialized: str = graph.serialize(format="xml")
graph_xml_parsed: Graph = Graph().parse(data=xml_serialized, format="xml")

# pass
assert all(o.datatype for o in graph_xml_parsed.objects())

## 3. check literal type of json-ld parsed graph object (fails)
json_ld_serialized: str = graph.serialize(format="json-ld")
graph_json_parsed: Graph = Graph().parse(data=json_ld_serialized, format="json-ld")

# fail
assert all(o.datatype for o in graph_json_parsed.objects())

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting feedbackMore feedback is needed from the author of the PR or Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions