doc/planning/alternatives-to-$.md
When sending metadata along with arbitrary JSON objects, a collision of property names may occur. For example, the driver system can't place a "type" property on an arbitrary response coming from a driver because that might also be the name of a property in the response.
{
"type": "api:thing",
"version": "v1.0.0",
"some": "info"
}
Reserved words. Drivers need to know their response can't have
keys like type or version. If we'd like to add more meta
keys in the future we need to verify that no existing drivers
use the new key we'd like to reserve. If we have have such features
as user-submitted drivers this will be impossibe.
A meta key as a single reserved word could work, which is one
of the solutions discussed below.
The obvious solution is to return an object with a
head property and a body propery:
{
"head": {
"type": "api:thing",
"version": "v1.0.0"
},
"body": {
"some": "info"
}
}
I don't mind this solution. I've come up with some alternatives though, because this solution has a couple drawbacks:
/[A-Za-z_][A-Za-z0-9_]*/$ indicates the schema or class of
the object.{
"$": "api:thing",
"$version": "v1.0.0",
"some": "info"
}
$ might be surprising or confusing$)$_ instead of $
{
"_": "api:thing",
"_version": "v1.0.0",
"some": "info"
}
_ might be confusing_)_ is conventionally used for private property names,
so this might be a little less surprising_{
"type": "api:thing",
"version": "v1.0.0",
"value": {
"some": "info"
}
}
_ in this example, but instead of prefixing
meta properties they all go under one key.
{
"_": {
"type": "api:thing",
"version": "v1.0.0"
},
"some": "info"
}
_ might be confusing_)_ is conventionally used for private property names,
so this might be a little less surprising_ as an exact key