Search code examples
schema.orgjson-ld

Re-using JSON-LD knowledge data


I can't determine if it's possible to reference a pairs value after it has been defined.

For example if I create an address pair, can I then use a shorthand way of re-using that value?

"address": {
                        "@type": "PostalAddress",
                        "streetAddress": "14 Blue Street Road",
                        "addressLocality": "Nottingham",
                        "addressRegion": "Nottinghamshire
                        "postalCode": "NG73DT",
                        "addressCountry": "United Kingdom"
                    },
                    "foundingLocation": "@address",

Solution

  • Yes, this is possible. JSON-LD links nodes using properties. Nodes are either value objects (e.g., dates, times, numbers, etc.) or node objects, such as your PostalAddress above. All nodes have an identifier, either explicit or implement, specified using the @id property. The JSON-LD Flattening algorithm, among others, has a process where it removes embedded node definitions, and replaces them with references, creating a blank node as required. A reference is basically just a node containing only the @id property. Your example above could be re-written by adding a blank node to the PostalAddress:

    "address": {
                        "@id": "_:n1",
                        "@type": "PostalAddress",
                        "streetAddress": "14 Blue Street Road",
                        "addressLocality": "Nottingham",
                        "addressRegion": "Nottinghamshire
                        "postalCode": "NG73DT",
                        "addressCountry": "United Kingdom"
                    },
                    "foundingLocation": "@address",
    

    You can then reference this from foundingLocation as follows:

    "address": {
                        "@id": "_:n1",
                        "@type": "PostalAddress",
                        "streetAddress": "14 Blue Street Road",
                        "addressLocality": "Nottingham",
                        "addressRegion": "Nottinghamshire
                        "postalCode": "NG73DT",
                        "addressCountry": "United Kingdom"
                    },
                    "foundingLocation": {"@id": "_:n1"}