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?










share|improve this question



























    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?










    share|improve this question

























      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 3:13









      unor

      65.3k17135239




      65.3k17135239










      asked Nov 10 at 21:00









      Graham

      1,68431825




      1,68431825






















          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 a schema:Person is fictional, you could add a ex:FictionalThing type to that entity.


            • Use a sub-type instead. To convey that a schema:Person is fictional, you could define ex:FictionalPerson to be a sub-type of schema:Person, and only¹ use ex:FictionalPerson.


          • For properties:


            • Add a property. To provide a nickname for a schema:Person, you could add a ex:nickname property.²


            • Use a sub-property instead. You could define ex:nickname to be a sub-property of schema:additionalName, and only¹ use ex: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.






          share|improve this answer




















            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
            );



            );













            draft saved

            draft discarded


















            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 a schema:Person is fictional, you could add a ex:FictionalThing type to that entity.


              • Use a sub-type instead. To convey that a schema:Person is fictional, you could define ex:FictionalPerson to be a sub-type of schema:Person, and only¹ use ex:FictionalPerson.


            • For properties:


              • Add a property. To provide a nickname for a schema:Person, you could add a ex:nickname property.²


              • Use a sub-property instead. You could define ex:nickname to be a sub-property of schema:additionalName, and only¹ use ex: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.






            share|improve this answer
























              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 a schema:Person is fictional, you could add a ex:FictionalThing type to that entity.


                • Use a sub-type instead. To convey that a schema:Person is fictional, you could define ex:FictionalPerson to be a sub-type of schema:Person, and only¹ use ex:FictionalPerson.


              • For properties:


                • Add a property. To provide a nickname for a schema:Person, you could add a ex:nickname property.²


                • Use a sub-property instead. You could define ex:nickname to be a sub-property of schema:additionalName, and only¹ use ex: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.






              share|improve this answer






















                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 a schema:Person is fictional, you could add a ex:FictionalThing type to that entity.


                  • Use a sub-type instead. To convey that a schema:Person is fictional, you could define ex:FictionalPerson to be a sub-type of schema:Person, and only¹ use ex:FictionalPerson.


                • For properties:


                  • Add a property. To provide a nickname for a schema:Person, you could add a ex:nickname property.²


                  • Use a sub-property instead. You could define ex:nickname to be a sub-property of schema:additionalName, and only¹ use ex: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.






                share|improve this answer












                In general, there are four ways how it can be approached:



                • For types (aka. classes):


                  • Add a type. To convey that a schema:Person is fictional, you could add a ex:FictionalThing type to that entity.


                  • Use a sub-type instead. To convey that a schema:Person is fictional, you could define ex:FictionalPerson to be a sub-type of schema:Person, and only¹ use ex:FictionalPerson.


                • For properties:


                  • Add a property. To provide a nickname for a schema:Person, you could add a ex:nickname property.²


                  • Use a sub-property instead. You could define ex:nickname to be a sub-property of schema:additionalName, and only¹ use ex: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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 3:12









                unor

                65.3k17135239




                65.3k17135239



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo