I'm investigating the use of JSON-LD and Hydra for use as an API payload. It seems to be very promising, but I'm struggling with one thing - how to extend pre-defined types.
For example, I have users. It seems reasonable to model them as "@type": "http://schema.org/Person" - since users are people. But I also want to have some properties on my users that are not defined on that type - e.g. user account information.
I know that I can give a resource multiple types, so I can define my own vocabulary that defines a type of "User" having this information, but is that the correct way to achieve this? Or is there a better way using JSON-LD to achieve this goal?
In general, there are four ways how it can be approached:
schema:Personis fictional, you could add aex:FictionalThingtype to that entity.schema:Personis fictional, you could defineex:FictionalPersonto be a sub-type ofschema:Person, and only¹ useex:FictionalPerson.schema:Person, you could add aex:nicknameproperty.²ex:nicknameto be a sub-property ofschema:additionalName, and only¹ useex:nickname.²It’s a good practice to reuse existing RDF types/properties. If there is no suitable term/vocabulary, define your own.
In your specific case, it seems to me that you need a type for representing a user account, as a
schema:Personcould have multiple accounts, and there is probably no user data that is true for all user accounts of that person. So you might want to consider using an entity for representing a user account, and a property to connect such an account with aschema:Person.You could, for example, use the property
foaf:accountto add afoaf:OnlineAccountto theschema:Person:¹ Or use it in addition to the super-type/super-property, which is typically a good idea if you want to support consumers who don’t read your own vocabulary first.
² You don’t have to add another type next to
schema:Personfor this purpose, as you can freely mix types and properties from different vocabularies. Also note that you can define the domain and range of the property, which allows you to "implicitly" add types to the referencing/referenced entities. In the example above, a consumer who knows the FOAF vocabulary will add the typefoaf:Agentto the entitiy with the typeschema:Person, because it’s the domain of the propertyfoaf:account.