Open grenik opened 8 months ago
Without going into your examples too far, you might look at Nested Properties which an allow nesting at arbitrary depth.
Nested properties require that I know their names and define them explicitly in the @context
, but in my case I receive JSONs with arbitrary properties: an indexed maps nested inside another indexed map (callbacks in my example are first indexed by the callback name and then by a path). I need to convert property names (the keys used to index objects) to RDF property values.
I can achieve it using Property-based data indexing via @container: @index
and @index: URI
, but only for one level, while the data I receive often contain multi-level maps, as shown in my examples.
Specification can be extended to model my case by allowing array values for @index
:
{
"@context": {
"mapWith2LevelsAndSemanticKeys": {
"@id": "...",
"@container": "@index",
"@index": ["schema:firstLevelKey", "schema:secondLevelKey"] // this already tells JSON-LD processor that map has 2 levels
},
}
}
If keys at certain levels can be ignored (have no semantic meaning), this could also be modelled by placing null
s in @index
.
{
"@context": {
"mapWithFourLevels": {
"@id": "...",
"@container": "@index",
"@index": [null, "schema:secondLevelKey", null, "schema:fourthLevelKey"] // skip keys on level 1 and 3
},
}
}
Real-life example:
For instance, callbacks
in OpenAPI are first indexed by the callback name and then by the path (see spec, example)
Here is a simplified example of an API description with a single-level map pahts
and a 2-level map callbacks
:
{
"paths": {
"/registration": {
"post": "registers user",
"delete": "deletes account"
},
"/login": {
"post": "login",
"delete": "logout"
}
},
"callbacks": {
"Registration Callback": {
"/onRegistration": {
"post": "called when registered",
"delete": "called when account is deleted"
}
},
"Login Callback": {
"/onLogin": {
"post": "when logged in"
},
"/onLogout": {
"post": "when logged out"
}
}
}
}
@grenik sadly at this point, I don't think JSON-LD can support that structure. You'd need to convert it into something with less "implied"/structural semantics.
@gkellogg this is certainly a common case in human-facing JSON (well...YAML...) formats like OpenAPI, so I do wonder what it would take to support it. Everything I can imagine right now looks rather odd in the context definition, but maybe there's a way we could explore for doing multiple "stacked" indexes somehow. Something fun to explore, anyhow. 😀
Is there a way to model map of maps?
I see only single-level maps: Property-based data indexing
But maps often have 2+ levels of indexing. Simplified example: animals are indexed by the size, and then by the color.
expansion result: