Migrating from GraphML

A GraphML <data> section is migrated by attaching the values directly to the structural element, using the name attribute from the GraphML <keys> section.

Here is a GraphML keys declaration section using all possible data types:

<graph>
  <key id="k1" for="node" name="myString" type="xs:string"/>
  <key id="k2" for="node" name="myInt" type="xs:int"/>
  <key id="k3" for="node" name="myDouble" type="xs:double"/>
  <key id="k4" for="node" name="myBoolean" type="xs:boolean"/>
  <key id="k5" for="node" name="myLong" type="xs:long"/>
  <key id="k6" for="node" name="myFloat" type="xs:float"/>
</graph>

and here is the section where we assign a node 'n1' all this data:

<node id="n1">
  <data key="k1">Hello</data>
  <data key="k2">42</data>
  <data key="k3">3.14</data>
  <data key="k4">true</data>
  <data key="k5">12345678901234567890</data>
  <data key="k6">1.23</data>
</node>

this is expressed in Connected JSON as

{
    "nodes": [
      {
        "id": "n1",
        "myString": "Hello",
        "myInt": 42,
        "myDouble": 3.14,
        "myBoolean": true,
        "myLong": 12345678901234567890,
        "myFloat": 1.23
      }
    ]
}

and the <keys> section is omitted. JSON carries enough type information in its values. Also, we moved to a schema-less world where the effective schema (w.g., which properties are used on nodes?) can be inferred from the data.

Some tools extend GraphML by using XML namespaces and embedding, e.g., layout or style data within a graphml file. Such data should be expressed as JSON in any properties, not defined by this spec.
GraphML has description element in several places. These simply map to a description property in Connected JSON.
Ideas On Mapping CJ to GraphML

For backward compatibility, CJ can be expressed as GraphML. For the most part, this is almost a 1:1 mapping. The challenging part is the mapping of the data types:

CJ

GraphML

Type system

JSON

XML Schema

Schema required?

schema-less

Types defined in <keys> section

Compound types

yes

no

Types

Any JSON

xs:string, xs:int, xs:double, xs:boolean, xs:long, xs:float

Conclusions
  1. Some data types in JSON (object, array) cannot be represented in GraphML.

  2. Data can in GraphML only be added to node, edge, and graph elements. Data on other elements can only be stored in GraphML as custom XML attributes.

  3. A schema needs to be inferred from data and made available to the GraphML writer.

Strategy

Emit all CJ into a buffer and build type observations for node, edge and graph elements.

Observed JSON Mapped XML Schema Type

All boolean

xs:boolean

All number, no decimals, < MAX_INT

xs:int

All number, no decimals

xs:long

All number, < MAX_FLOAT

xs:float

All number

xs:double

All string

xs:string

Mix of types

xs:string

with MAX_INT = 2147483647 and MAX_FLOAT = 3.4028235E38 as defined in https://www.w3.org/TR/xmlschema11-2/#double