Work with PROV-JSON¶
PROV-JSON is the default format for
serialize() and
deserialize(). It needs no extra.
Round trip¶
import prov.model as pm
document = pm.ProvDocument()
document.set_default_namespace("http://example.org/")
document.entity("e1")
document.serialize("document.json") # format="json" is the default
loaded = pm.ProvDocument.deserialize("document.json")
assert loaded == document
Read and write documents covers strings, streams and prov.read().
Options¶
Keyword arguments go to json.dump, so indent=2 pretty-prints:
print(document.serialize(indent=2))
Errors¶
Valid JSON with the wrong structure raises
prov.serializers.provjson.ProvJSONException:
from prov.serializers.provjson import ProvJSONException
try:
pm.ProvDocument.deserialize(content='{"entity": "oops"}', format="json")
except ProvJSONException as e:
print(f"{type(e).__name__}: {e}")
ProvJSONException: The 'entity' value must be a JSON object; found str: 'oops'
Limitations¶
None. Every concept in Conformance round-trips through PROV-JSON.