-
-
Couldn't load subscription status.
- Fork 12
Description
Subobjects are helpful to aggregate dependant objects to a main object and we can use a subschema or $ref to restrict their structure.
{
"$id": "Address",
"properties": {
"...": {}
}
}{
"$id": "Person",
"properties": {
"address": { "$ref": "Address" }
}
}However, this is often not a good solution for independant but linked object, e. g. a friend is a standalone object that should not be nested or duplicated as a subobject.
{
"$id": "Person",
"properties": {
"friend": { "$ref": "Person" }
}
}As a solution you can make friend a property of type IRI that points to the target Person:
{
"$id": "Person",
"properties": {
"friend": { "type": "string", "format": "iri" }
}
}But in this case we will loose the information what schema an application should expect for the object pointed to by the given IRI. To solve this problem my suggestion would be a keyword somehow inbetween $ref (indicating a target schema) and $dynamicRef (only validated at runtime), e. g. $valuesFrom (similar to owl:someValuesFrom) or $range (similar to rdfs:range):
{
"$id": "Person",
"properties": {
"friend": { "type": "string", "format": "iri", "$valuesFrom": "Person" }
}
}This would be helpful e. g. for web forms to generate the target object ad-hoc with the indicated schema but store only the reference (IRI) in the main object or in generated class structures where the iri is replaced with an object-memory-reference at runtime after creating instances from json input.
This would also close a main gap to schema languages for linked data (OWL/SHACL) so that interoperability (in combination with JSON-LD) could be achieved (see also json-ld/json-ld.org#612 (comment)).
Related: