0

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",
unor
  • 92,415
  • 26
  • 211
  • 360
Showcase Imagery
  • 372
  • 2
  • 19
  • Possible duplicate of [Schema.org JSON-LD reference](http://stackoverflow.com/questions/34761970/schema-org-json-ld-reference) – unor Dec 05 '16 at 08:31

1 Answers1

1

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"}
Gregg Kellogg
  • 1,831
  • 12
  • 8
  • not working @greggkellogg i get this error **foundingLocation PostalAddress is not a known valid target type for the foundingLocation property.** in google's structured data tool – Showcase Imagery Dec 05 '16 at 19:37
  • Any ideas? @greggkellogg – Showcase Imagery Dec 06 '16 at 16:03
  • Sorry to let this languish. Create an example at http://json-ld.org/playground, and you can post a shorted URL to it here, which allows issues to be looked at in more depth. If Google's SDTT does something different, that's an issue with them, not JSON-LD. – Gregg Kellogg Apr 12 '17 at 04:51