Adding custom properties to an existing type in JSON-LD
up vote
2
down vote
favorite
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?
rdf ontology json-ld structured-data vocabulary
add a comment |
up vote
2
down vote
favorite
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?
rdf ontology json-ld structured-data vocabulary
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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?
rdf ontology json-ld structured-data vocabulary
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?
rdf ontology json-ld structured-data vocabulary
rdf ontology json-ld structured-data vocabulary
edited Nov 11 at 3:13
unor
65.3k17135239
65.3k17135239
asked Nov 10 at 21:00
Graham
1,68431825
1,68431825
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
In general, there are four ways how it can be approached:
- For types (aka. classes):
Add a type. To convey that aschema:Person
is fictional, you could add aex:FictionalThing
type to that entity.
Use a sub-type instead. To convey that aschema:Person
is fictional, you could defineex:FictionalPerson
to be a sub-type ofschema:Person
, and only¹ useex:FictionalPerson
.
- For properties:
Add a property. To provide a nickname for aschema:Person
, you could add aex:nickname
property.²
Use a sub-property instead. You could defineex:nickname
to 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:Person
could 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 a schema:Person
.
You could, for example, use the property foaf:account
to add a foaf:OnlineAccount
to the schema:Person
:
"@context": "http://www.w3.org/2013/json-ld-context/rdfa11",
"@type": "schema:Person",
"schema:name": "Name of the person",
"foaf:account":
"@type": "foaf:OnlineAccount",
"schema:name": "Name of the online account"
¹ 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:Person
for 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 type foaf:Agent
to the entitiy with the type schema:Person
, because it’s the domain of the property foaf:account
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243358%2fadding-custom-properties-to-an-existing-type-in-json-ld%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
In general, there are four ways how it can be approached:
- For types (aka. classes):
Add a type. To convey that aschema:Person
is fictional, you could add aex:FictionalThing
type to that entity.
Use a sub-type instead. To convey that aschema:Person
is fictional, you could defineex:FictionalPerson
to be a sub-type ofschema:Person
, and only¹ useex:FictionalPerson
.
- For properties:
Add a property. To provide a nickname for aschema:Person
, you could add aex:nickname
property.²
Use a sub-property instead. You could defineex:nickname
to 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:Person
could 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 a schema:Person
.
You could, for example, use the property foaf:account
to add a foaf:OnlineAccount
to the schema:Person
:
"@context": "http://www.w3.org/2013/json-ld-context/rdfa11",
"@type": "schema:Person",
"schema:name": "Name of the person",
"foaf:account":
"@type": "foaf:OnlineAccount",
"schema:name": "Name of the online account"
¹ 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:Person
for 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 type foaf:Agent
to the entitiy with the type schema:Person
, because it’s the domain of the property foaf:account
.
add a comment |
up vote
1
down vote
In general, there are four ways how it can be approached:
- For types (aka. classes):
Add a type. To convey that aschema:Person
is fictional, you could add aex:FictionalThing
type to that entity.
Use a sub-type instead. To convey that aschema:Person
is fictional, you could defineex:FictionalPerson
to be a sub-type ofschema:Person
, and only¹ useex:FictionalPerson
.
- For properties:
Add a property. To provide a nickname for aschema:Person
, you could add aex:nickname
property.²
Use a sub-property instead. You could defineex:nickname
to 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:Person
could 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 a schema:Person
.
You could, for example, use the property foaf:account
to add a foaf:OnlineAccount
to the schema:Person
:
"@context": "http://www.w3.org/2013/json-ld-context/rdfa11",
"@type": "schema:Person",
"schema:name": "Name of the person",
"foaf:account":
"@type": "foaf:OnlineAccount",
"schema:name": "Name of the online account"
¹ 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:Person
for 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 type foaf:Agent
to the entitiy with the type schema:Person
, because it’s the domain of the property foaf:account
.
add a comment |
up vote
1
down vote
up vote
1
down vote
In general, there are four ways how it can be approached:
- For types (aka. classes):
Add a type. To convey that aschema:Person
is fictional, you could add aex:FictionalThing
type to that entity.
Use a sub-type instead. To convey that aschema:Person
is fictional, you could defineex:FictionalPerson
to be a sub-type ofschema:Person
, and only¹ useex:FictionalPerson
.
- For properties:
Add a property. To provide a nickname for aschema:Person
, you could add aex:nickname
property.²
Use a sub-property instead. You could defineex:nickname
to 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:Person
could 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 a schema:Person
.
You could, for example, use the property foaf:account
to add a foaf:OnlineAccount
to the schema:Person
:
"@context": "http://www.w3.org/2013/json-ld-context/rdfa11",
"@type": "schema:Person",
"schema:name": "Name of the person",
"foaf:account":
"@type": "foaf:OnlineAccount",
"schema:name": "Name of the online account"
¹ 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:Person
for 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 type foaf:Agent
to the entitiy with the type schema:Person
, because it’s the domain of the property foaf:account
.
In general, there are four ways how it can be approached:
- For types (aka. classes):
Add a type. To convey that aschema:Person
is fictional, you could add aex:FictionalThing
type to that entity.
Use a sub-type instead. To convey that aschema:Person
is fictional, you could defineex:FictionalPerson
to be a sub-type ofschema:Person
, and only¹ useex:FictionalPerson
.
- For properties:
Add a property. To provide a nickname for aschema:Person
, you could add aex:nickname
property.²
Use a sub-property instead. You could defineex:nickname
to 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:Person
could 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 a schema:Person
.
You could, for example, use the property foaf:account
to add a foaf:OnlineAccount
to the schema:Person
:
"@context": "http://www.w3.org/2013/json-ld-context/rdfa11",
"@type": "schema:Person",
"schema:name": "Name of the person",
"foaf:account":
"@type": "foaf:OnlineAccount",
"schema:name": "Name of the online account"
¹ 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:Person
for 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 type foaf:Agent
to the entitiy with the type schema:Person
, because it’s the domain of the property foaf:account
.
answered Nov 11 at 3:12
unor
65.3k17135239
65.3k17135239
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243358%2fadding-custom-properties-to-an-existing-type-in-json-ld%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown