Question re: @context and JSON-LD

Let's say for some contrived (but very real) reason, I want to add { "toot": "http://joinmastodon.org/ns#", "Emoji": "toot:Emoji" } to @context, but another member of @context might be { "toot": "http://joinmastodon.org/ns#", "focalPoint": ... }

Would it be acceptable if I just pushed my object to the end and assumed that JSON-LD parsers would correctly reduce it down to:

{
  "toot": "http://joinmastodon.org/ns#",
  "Emoji": "toot:Emoji",
  "focalPoint": ...
}

... or should I be adding in logic to detect the existing member defining toot and merge the Emoji property in?

in theory there’s no issue about having subsequent contexts redefining toot, which you can see by running the compaction algorithm on the JSON-LD playground with the normative context:

https://tinyurl.com/2bqnm5f6

In practice though it seems kinda wasteful if you have to reinclude the base namespace definition for every single extension property you wish to use. Why not just keep a map from namespace -> property definitions included and then have one context per namespace you’re including from?

1 Like