Motivation
Dgraph supports (optionally) the inclusion of RDF Types in the RDF dataset. However, this same feature does not exist in JSON. It would be interesting to have the same practicality using JSON. By indicating the scalar type in the dataset itself, so the parser identifies the scalar type and apply it. Preventing it from being automatically registered as a “default” type.
With that, we guarantee that JSON-DG* follows Closely the Dgraph’s RDF “standards/specs”. And Dgraph exports it nicely.
* I call “JSON-DG” as an allusion to “Dgraph’s JSON format”.
To support this, I take as an example of Dgraph’s support for markup in JSON itself. For example, Facet and language support.
{
"user|meta" : "32B55",
"rating@en": "tastes good"
}
Now, examples about this RFC:
This RDF
<0x01> <name> "Julian"^^<xs:string> .
<0x01> <age> "32"^^<xs:int> .
<0x01> <since> "1985-06-08"^^<xs:dateTime> .
in JSON becomes
{
"name@en^^<xs:string>": "Julian",
"age^^<xs:int>": "32",
"since^^<xs:dateTime>": "2020-01-02"
}
Or as JTriples approach, like
{
"name@en": "\"Julian\"^^<xs:string>",
"age": "\"32\"^^<xs:int>",
"since": "\"2020-01-02\"^^<xs:dateTime>"
}
This one looks nice, the first one would try to reuse the same approach the parse takes doing facets and language support. Maybe the first one is easier to implement.
About the JSON Scalar Types
Dgraph’s JSON today supports:
- string.
- int.
- float.
- object ( JSON object) # This creates edges.
- array. # This creates lists
- array of objects. # This creates edges.
- boolean.
- null/empty. #This is used in operations. Dgraph don’t have null.
Dgraph also needs:
<xs:dateTime>
.<xs:date>
.<geo:geojson>
<xs:password>
<xs:integer>
.- All basic types from W3C e.g
<http://www.w3.org/2001/XMLSchema#positiveInteger>
+ 8 others.
e.g:
<0x8> <password> "$2a$10$6qgJxpWfn.XtYyJN8ZBPTO83NzxHluMx01B8bi6K7EN.XDVpiCQkq"^^<xs:password> .
In RDF it exports right and imports right.
But in JSON, it breaks.
{
"uid":"0x8",
"password":"$2a$10$6qgJxpWfn.XtYyJN8ZBPTO83NzxHluMx01B8bi6K7EN.XDVpiCQkq"
}
Password type will be a string and Dgraph throw an error
Could not alter predicate: Error: Schema change not allowed from STRING to PASSWORD
GeoJSON example:
Dgraph exports like this
{
"uid":"0x3",
"loc":"{'type':'Point','coordinates':[-122.4220186,37.772318]}"
}
If we import this without a proper schema, the whole GeoJSON will be converted to String. At least, in this case we can transform it to Geo manually.
User Impact
The impact on the user would be small. Dgraph would continue to accept JSON without many definitions normally. But perhaps the user would want to export the JSON without RDF types. So it would be nice to provide a way to export pure JSON.
Research
JTriples References:
https://www.w3.org/wiki/JTriples
[
{
"s": "<http://example.org>",
"p": "<http://purl.org/dc/terms/title>",
"o": "\"Example Title\"@en"
}
]
[
{
"s": "<http://example.org>",
"p": "<http://purl.org/dc/terms/date>",
"o": "\"2010-12-02\"^^<http://www.w3.org/2001/XMLSchema#date>"
}
]
Rdfj References:
This one is very simple JSON RDF format, but I don’t think it reliable in terms of parsing.
e.g
{
"name": "Anna Wilder",
"homepage": "<http://example.org/about>",
"birthday": "1970-04-01^^http://www.w3.org/2001/XMLSchema-datatypes#date"
}
it adds the RDF Type in the value place, with no especial escaping strategy.
https://code.google.com/archive/p/backplanejs/wikis/Rdfj.wiki
Ping @dmai @ashishgoswami @mrjn