Compact JSON-LD
Purpose
The compact module provides a BaseModel class based on the BaseModel of pydantic.
Using this base class, one can define models for JSON-LD data in compacted form
such that any existing data can be validated and instantiated as a model instance.
Additionally, model instances can be manually created and dumped as compact JSON-LD data.
Terms
Terms such as ex:value are supported as well
by using the provided Field implementation derived from the pydantic.
from pydantic_jsonld.compact import BaseModel, Field
class MyModel(BaseModel):
value: int = Field(..., term="ex")
Context
This implementation provides no parsing or validation of contexts. As such, while any provided context is allowed, the context has no effect on the validation of defined models.
This is a deliberate decision as this would require implementing proper JSON-LD parsing which would vastly exceed the scope of this project.
It is recommended to either use the expanded models or to compact all data beforehand using packages such as PyLD or RDFlib if you need to handle JSON-LD with the same schema but vastly different contexts.
Limitations
This lack of context parsing causes a number of limitations for dealing with data with varying contexts.
Keywords
For the actual document data, the only supported keywords are
@direction, @id, @index, @language, @type, and @value.
Most notably, @list and @set are not supported as of now.
For the context, any keywords are supported, since no actual parsing of the context takes place.