Dear Otto,
What you are referring to, a serializer for any `Node` type to JSON,
doesn't exist (yet).
There is an open issue for this on the repository:
https://github.com/aiidateam/aiida-core/issues/5464
The function I linked only serializes the "attributes" of a node,
since that is what is stored as JSON in a database.
However, a node can of course also store files in the repository.
You could write your own generic serializer (essentially serializing
all attributes, extras and repository objects), however, a generic
deserializer is not possible.
Since `Data` can be subclassed, it is not possible to recreate an
instance without actually having the implementation of the subclass.
If you "just" need the JSON data on the other computer, you could
write an off-the-cuff serializer by doing something like:
import json
import pathlib
# Get information stored in the database
serialized = {
'pk': node.pk,
'uuid': node.uuid,
'label': node.label,
'description': node.description,
'node_type': node.node_type,
'node_type': node.node_type,
'process_type': node.process_type,
'extras': node.extras,
'attributes': node.attributes,
'objects': {}
}
# Get content from the repository
for root, dirnames, filenames in
node.base.repository.walk():
for filename in filenames:
key = pathlib.Path(root) / filename
with node.base.repository.open(key)
as handle:
serialized['objects'][str(key)]
= handle.read()
json.dumps(serialized)
Note that I haven't tested this and it isn't complete.
It doesn't include things like the `ctime`, `mtime` and the user and
computer of the node.
But maybe this can be useful for your use case.
Again though, this is not useful if you are looking to automatically
"reconstruct" the Python instance on the other side.
This generic approach doesn't exist yet and is not trivial without
updating all existing `Data` types.
Hope that helps,
Sebastiaan