Serialization of properties of properties

37 views
Skip to first unread message

Laura Morales

unread,
Jan 5, 2021, 9:31:03 PM1/5/21
to janus ml
The docs describes that properties can have properties too. https://docs.janusgraph.org/advanced-topics/advschema/#multi-properties
For example:

alice -age-> 23 -source-> foo
-address-> "something" -source-> bar

My question is, how are these properties of properties serialized in GraphML and GraphSON? In JSON properties are simple key-value pairs, for example

{
"alice": {
"age": 23,
"address": "something
}
}

so I don't really understand where would the "source" properties be added. Thanks.

Florian Hockmann

unread,
Jan 6, 2021, 6:30:56 AM1/6/21
to JanusGraph users
GraphSON is a serialization format from TinkerPop to serialize graph objects. It doesn't serialize properties as simple key-value pairs. To try out how vertex properties with meta properties are serialized in GraphSON, we can create your vertex and then dump the test graph to disk in GraphSON format with the Gremlin Console:

gremlin> g.addV().property('name','alice').property('age',23).property('address','something')
==>v[11]
gremlin> g.V().has('name','alice').properties('address').property('source','bar')
==>vp[address->something]
gremlin> g.V().has('name','alice').properties('age').property('source','foo')
==>vp[age->23]
gremlin> g.V().properties().properties()
==>p[source->bar]
==>p[source->foo]
gremlin> g.io("graph_out.json").write().iterate()

The resulting JSON then looks like this:

{
    "id": {
        "@type": "g:Int64",
        "@value": 11
    },
    "label": "vertex",
    "properties": {
        "address": [
            {
                "id": {
                    "@type": "g:Int64",
                    "@value": 12
                },
                "value": "something",
                "properties": {
                    "source": "bar"
                }
            }
        ],
        "name": [
            {
                "id": {
                    "@type": "g:Int64",
                    "@value": 13
                },
                "value": "alice"
            }
        ],
        "age": [
            {
                "id": {
                    "@type": "g:Int64",
                    "@value": 14
                },
                "value": {
                    "@type": "g:Int32",
                    "@value": 23
                },
                "properties": {
                    "source": "foo"
                }
            }
        ]
    }
}

As you can see, the vertex properties are stored as a map with the names of the properties as their keys and the values are a list of vertex property objects. It's a list because you can have multiple values for the same properties. This could be used in your example when different sources give you different addresses for the same person. Such a vertex property object can then have additional properties which hold the meta properties.
You can get more information about GraphSON in the TinkerPop IO docs. I used the current version 3.0 of GraphSON here which is also the default version of JanusGraph.

These IO docs also document how TinkerPop implements GraphML and they mention that some TinkerPop features are not supported by GraphML which includes meta-properties.
Reply all
Reply to author
Forward
0 new messages