ontolutils.classes.thing.Thing.model_dump_jsonld

Thing.model_dump_jsonld(context: Optional[Dict] = None, exclude_none: bool = True, rdflib_serialize: bool = False, resolve_keys: bool = True, base_uri: Optional[Union[str, AnyUrl]] = None, indent: int = 4) str

Similar to model_dump_json() but will return a JSON string with context resulting in a JSON-LD serialization. Using rdflib_serialize=True will use the rdflib to serialize. This will make the output a bit cleaner but is not needed in most cases and just takes a bit more time (and requires an internet connection.

Note, that if rdflib_serialize=True, then a blank node will be generated if no ID is set.

context: Optional[Union[Dict, str]]

The context to use for the JSON-LD serialization. If a string is given, it will be interpreted as an import statement and will be added to the context.

exclude_none: bool=True

Exclude fields with None values

rdflib_serialize: bool=False

If True, the output will be serialized using rdflib. This results in a cleaner output but is not needed in most cases and just takes a bit more time (and requires an internet connection). Will also generate a blank node if no ID is set.

resolve_keys: bool=False

If True, then attributes of a Thing class will be resolved to the full IRI and explained in the context.

indent: int=4

The indent of the JSON-LD string

base_uri: Optional[HttpUrl]=None

The base URI to use for blank nodes (only used if no ID is set). This is useful, because blank nodes are not globally unique and can lead to problems when merging data from different sources.

See also

Thing.get_jsonld_dict

str

The JSON-LD string