### URN Example Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html An example of a Uniform Resource Name (URN) using the 'urn:uuid:' scheme, which identifies a resource without locating it. ```text urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6 ``` -------------------------------- ### Interactive Example Button Logic Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html JavaScript code to handle the selection and display of interactive examples within tabs. It toggles the 'selected' class on buttons and their corresponding content panels. ```javascript document.addEventListener("DOMContentLoaded", () => { // Add example button selection logic for (const button of document.querySelectorAll(".ds-selector-tabs .selectors button")) { button.onclick = () => { const ex = button.closest(".ds-selector-tabs"); ex.querySelector("button.selected").classList.remove("selected"); ex.querySelector(".selected").classList.remove("selected"); button.classList.add('selected'); ex.querySelector("." + button.dataset.selects).classList.add("selected"); } } // Toggle show/hide changes for (const elem of document.querySelectorAll(".show-changes")) { elem.onclick = () => { if (elem.classList.contains("selected")) { // Remove highlight class from elements having "changed" class elem.classList.remove("selected"); for (const changed of document.querySelectorAll(".changed")) { changed.classList.remove("highlight"); } } else { // Add highlight class to elements having "changed" class elem.classList.add("selected"); for (const changed of document.querySelectorAll(".changed")) { changed.classList.add("highlight"); } } } } }); ``` -------------------------------- ### RDF Dataset Example Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? This is an example of an RDF dataset structure that can be encoded in JSON-LD. It defines two distinct graphs with associated RDF statements. ```turtle { a foaf:Person; foaf:name "Manu Sporny", foaf:knows . } { a foaf:Person; foaf:name "Gregg Kellogg", foaf:knows . } ``` -------------------------------- ### Term-to-IRI Expansion Example Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates how JSON keys matching terms in the active context are expanded to IRIs. Keys not found in the context are ignored. ```json { "@context": { "schema": "http://schema.org/" }, "@id": "_:b0", "schema:name": "Manu Sporny" } ``` -------------------------------- ### Compacted JSON-LD with Schema.org Vocabulary Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html An example of a compacted JSON-LD document using the Schema.org vocabulary, demonstrating how terms are mapped to IRIs. ```json { "@context": { "schema": "http://schema.org/", "name": "schema:name", "url": "schema:url", "image": "schema:image" }, "@id": "_:b0", "schema:image": "http://manu.sporny.org/images/manu.png", "schema:name": "Manu Sporny", "schema:url": "http://manu.sporny.org/" } ``` -------------------------------- ### Graph with Unidentified Named Graphs using @none Index Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html This example demonstrates using the `@none` index for graphs that do not have an explicit `@index` key. It shows how multiple unidentified named graphs can be represented, noting that their content will be merged upon compaction if they share the same `@none` index. ```json { "@context": { "@vocab": "http://schema.org/", "@index": "@none" }, "@graph": { "@none": [ { "@id": "http://example.com/", "@type": "Blog", "schema:blogPost": [ "_:b0", "_:b1" ] }, { "@id": "_:b0", "@type": "BlogPosting", "schema:articleBody": "World commodities were up today with heavy trading of crude oil...", "schema:wordCount": 1539 }, { "@id": "_:b1", "@type": "BlogPosting", "schema:articleBody": "Die Werte an Warenbörsen stiegen im Sog eines starken Handels von Rohöl...", "schema:wordCount": 1204 } ] } } ``` -------------------------------- ### JSON-LD Dataset with Backwards-Compatible Context Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? A JSON-LD example demonstrating a backwards-compatible approach to representing datasets using a top-level map and a custom 'dataset' context. The 'dataset' key is mapped to '@graph' with '@container' set to ['@graph', '@id']. ```json { "@context": { ... "dataset": {"@id": "@graph", "@container": ["@graph", "@id"]} }, "dataset" : { "URL1" : { Some RDF statements here }, "URL2" : [ { We could also define a bush just like above }, { } ], "@none" : [{ Default graph statements here }] } } ``` -------------------------------- ### Property-Scoped Context Example Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Shows a property-scoped context where a specific property ('schema:name') uses a different context for its values, allowing localized definitions. ```json { "@context": { "schema": "http://schema.org/", "foaf": "http://xmlns.com/foaf/0.1/", "name": { "@id": "schema:name", "@context": { "schema": "http://schema.org/", "foaf": "http://xmlns.com/foaf/0.1/" } }, "topic": "foaf:topic", "interest": "foaf:interest" }, "schema:name": "JSON-LD", "foaf:topic": "Linking Data", "_:b0": { "schema:name": "Manu Sporny", "foaf:interest": "https://www.w3.org/TR/json-ld11/" } } ``` -------------------------------- ### Default Graph with Indexed Named Graphs Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html This example shows a default graph referencing multiple named graphs using an index map. It illustrates the structure for associating blog posts with different language versions via an index. ```json { "@context": { "@vocab": "http://schema.org/", "@index": "@id" }, "@graph": { "http://example.com/": { "@id": "http://example.com/", "@type": "Blog", "schema:blogPost": [ "_:b0", "_:b1" ] }, "_:b0": { "@id": "http://example.com/posts/1/de", "@type": "BlogPosting", "schema:articleBody": "Die Werte an Warenbörsen stiegen im Sog eines starken Handels von Rohöl...", "schema:wordCount": 1204 }, "_:b1": { "@id": "http://example.com/posts/1/en", "@type": "BlogPosting", "schema:articleBody": "World commodities were up today with heavy trading of crude oil...", "schema:wordCount": 1539 } } } ``` -------------------------------- ### RDF to Turtle Serialization Example Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html This Turtle syntax represents RDF triples derived from a JSON-LD document after expansion and flattening. It demonstrates how node objects are converted into RDF triples. ```turtle @prefix ex: . @prefix rdf: . ex:a rdf:type ex:Type ; ex:name "Alice" ; ex:age 30 . ex:b rdf:type ex:Type ; ex:name "Bob" . ex:c rdf:type ex:Type ; ex:name "Charlie" . ``` -------------------------------- ### JSON-LD @graph with additional top-level terms Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? Example where @graph is used alongside other top-level terms, resulting in an RDF dataset. ```json { "@context" : {...} "generatedAt": "2012-04-09", "@id": "http://www.example.org/", "@graph": [ { "@id": "http://manu.sporny.org/about#manu", ... }, { "@id": "http://greggkellogg.net/foaf#me", ..., } ] } ``` -------------------------------- ### JSON-LD @container: @graph usage Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? Example of using the @graph container to generate named graphs within a dataset. ```json "@context" { "claim": { "@id": "https://w3id.org/credentials#claim", "@container": "@graph" } }, "generatedAt": "2012-04-09", "@id": "http://www.example.org/", "claim": [ { "@id": "http://manu.sporny.org/about#manu", ... }, { "@id": "http://greggkellogg.net/foaf#me", ..., } ] ``` -------------------------------- ### JSON-LD Bush Definition Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? A basic JSON-LD structure for defining a 'bush', which represents a collection of RDF statements. This example shows two distinct entries, each with an '@id' and a property. ```json [ { "@id" : "http://www.example.org/1", "http://a.b.c" : "something" },{ "@id" : "http://www.example.org/2", "http://d.e.f" : "something" } ] ``` -------------------------------- ### Using IRI as Key in Context Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates using a full IRI as a key in a context definition, which requires direct string comparison for matching. ```json { "@context": { "http://xmlns.com/foaf/0.1/homepage": { "@type": "@id" } }, "http://xmlns.com/foaf/0.1/homepage": "http://example.com/user/home" } ``` -------------------------------- ### Using Relative IRI References Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Shows how relative IRI references are resolved against the base IRI of the document. In this case, '../' resolves to the parent directory. ```json { "@context": { "@base": "http://example.com/about/", "name": "http://schema.org/name", "homepage": "http://schema.org/url", "image": "http://schema.org/image" }, "@id": "_:b0", "name": "Manu Sporny", "homepage": "../", "image": "../images/manu.png" } ``` -------------------------------- ### Illegal Circular Context Definition Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html An example of an illegal context definition due to a circular dependency between term definitions. ```json { "@context": { "term1": { "@id": "http://example.com/term2" }, "term2": { "@id": "http://example.com/term1" } } } ``` -------------------------------- ### JSON-LD @graph as a top-level term Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? Example of using @graph at the top level without other statements to represent an RDF graph. ```json { "@context" : {...} "@graph": [ { "@id": "http://manu.sporny.org/about#manu", ... }, { "@id": "http://greggkellogg.net/foaf#me", ..., } ] } ``` -------------------------------- ### Flattening a JSON-LD Document Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Example of flattening a JSON-LD document, collecting all properties of a node into a single map and labeling blank nodes. ```json { "@context": { "name": "http://schema.org/name", "schema": "http://schema.org/" }, "@id": "http://example.com/person/1", "name": "Person", "schema:jobTitle": "Developer", "schema:affiliation": { "@id": "http://example.com/organization/1" } } ``` ```json { "@context": { "name": "http://schema.org/name", "schema": "http://schema.org/" }, "@id": "http://example.com/person/1", "@type": "@json", "name": "Person", "jobTitle": "Developer", "affiliation": { "@id": "http://example.com/organization/1" } } ``` -------------------------------- ### GeoJSON Feature with Nested Coordinates Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Example of a GeoJSON Feature demonstrating nested lists for coordinates, requiring recursive list definitions in JSON-LD. ```json { "type": "Feature", "bbox": [-10.0, -10.0, 10.0, 10.0], "geometry": { "type": "Polygon", "coordinates": [ [ [-10.0, -10.0], [10.0, -10.0], [10.0, 10.0], [-10.0, -10.0] ] ] } ####//...#### } ``` -------------------------------- ### Indexing Values with a Map Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Shows how to compact a JSON-LD document by using a map for properties with multiple values, indexed by language tags. ```json { "@context": { "label": { "@container": "@index" } }, "@id": "http://example.com/person/1", "label": { "en": "Person", "fr": "Personne" } } ``` -------------------------------- ### Using Compact IRI for Term Definition and Type Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Shows how a compact IRI can be used to declare both the IRI for a term and its associated `@type`. ```json { "@context": { "foaf": "http://xmlns.com/foaf/0.1/", "foaf:age": { "@id": "http://example.com/vocab/age", "@type": "xsd:integer" } }, "foaf:age": 42 } ``` -------------------------------- ### Represent Multiple Values with Different Types Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html A property in JSON-LD can have values of different types, including strings, language-tagged strings, and URIs, as demonstrated in this example. ```json { "@context": { "@vocab": "http://example.org/name" }, "@id": "http://example.org/people#michael", "name": [ "Michael", "Mike", { "@value": "Miguel", "@language": "es" }, "https://www.wikidata.org/wiki/Q4927524", { "@value": "42", "@type": "xsd:integer" } ] } ``` -------------------------------- ### Compacting Reverse Properties Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates how to compact a JSON-LD document by expressing relationships in reverse, eliminating the @reverse property. ```json { "@context": { "children": { "@reverse": "parent" } }, "@id": "http://example.com/person/1", "children": [ { "@id": "http://example.com/person/2" } ] } ``` -------------------------------- ### Use Full IRI Keys for Properties Source: https://context7.com/w3c/json-ld-syntax/llms.txt Properties can be specified using full IRIs directly as keys without needing context definitions. ```json { "http://schema.org/name": "Manu Sporny", "http://schema.org/url": { "@id": "http://manu.sporny.org/" }, "http://schema.org/image": { "@id": "http://manu.sporny.org/images/manu.png" } } ``` -------------------------------- ### Term Selection for Compaction Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Shows how JSON-LD compaction uses term definitions to select appropriate properties based on @container, @type, and @language specifications. ```json { "@context": { "integer": { "@type": "xsd:integer", "@container": "@set" }, "english": { "@language": "en" }, "date": { "@type": "xsd:date" }, "iri": { "@type": "@id" } }, "@id": "http://example.com/person/1", "integer": [1, 2], "english": "Person", "date": "2014-04-01T01:00:00Z", "iri": "http://example.com/person/2" } ``` -------------------------------- ### Normalizing Values as Objects Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Illustrates compacting a JSON-LD document while retaining object representations for values, using "@type": "@none". ```json { "@context": { "name": { "@type": "@none" } }, "@id": "http://example.com/person/1", "name": "Person" } ``` -------------------------------- ### Implement Language Maps with @container Source: https://context7.com/w3c/json-ld-syntax/llms.txt Indexes values by language tag, allowing for multilingual content support. ```json { "@context": { "vocab": "http://example.com/vocab/", "label": { "@id": "vocab:label", "@container": "@language" } }, "@id": "http://example.com/queen", "label": { "en": "The Queen", "de": [ "Die Königin", "Ihre Majestät" ] } } ``` -------------------------------- ### Using 'xsd' Namespace for Typed Values Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates defining and using a namespace alias ('xsd') within a context for coercing property values to specific types, such as integers. ```json { "@context": { "xsd": "http://www.w3.org/2001/XMLSchema#", "age": { "@id": "http://example.com/vocab/age", "@type": "xsd:integer" } }, "age": 42 } ``` -------------------------------- ### Represent values as strings Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Shows how compaction simplifies value objects into native JSON types. ```json { "http://example.org/name": [ { "@value": "Manu Sporny" } ], "http://example.org/age": [ { "@value": "1" } ], "http://example.org/isAlive": [ { "@value": "true" } ], "http://example.org/plain": [ { "@value": "plain" } ] } ``` ```json { "@context": { "name": "http://example.org/name", "age": { "@id": "http://example.org/age", "@type": "http://www.w3.org/2001/XMLSchema#integer" }, "isAlive": { "@id": "http://example.org/isAlive", "@type": "http://www.w3.org/2001/XMLSchema#boolean" } } } ``` ```json { "@context": { "name": "http://example.org/name", "age": { "@id": "http://example.org/age", "@type": "http://www.w3.org/2001/XMLSchema#integer" }, "isAlive": { "@id": "http://example.org/isAlive", "@type": "http://www.w3.org/2001/XMLSchema#boolean" } }, "name": "Manu Sporny", "age": 1, "isAlive": true, "plain": "plain" } ``` -------------------------------- ### Using @type with a Context-Defined Term Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Shows how the value of a `@type` key can be a term defined in the active context, allowing for more concise and abstract type definitions. ```json { "@context": { "schema": "http://schema.org/" }, "@id": "http://example.org/places#BrewEats", "@type": "schema:Person" } ``` -------------------------------- ### JSON-LD Bush with Referenced Context Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? An advanced JSON-LD structure demonstrating how to define a 'bush' using a referenced context. The context is defined separately and then applied to individual entries. ```json [ { "@context" : { "@id" : "_:a" ... } }, { "@context" : "_:a", "@id" : "http://www.example.org/1", "http://a.b.c" : "something" },{ "@context" : "_:a", "@id" : "http://www.example.org/2", "http://d.e.f" : "something" } ] ``` -------------------------------- ### Assigning Multiple Types to a Node Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates how to assign multiple types to a single node using an array for the `@type` keyword. This is useful when a resource conforms to multiple vocabularies or classifications. ```json { "@context": { "schema": "http://schema.org/", "foaf": "http://xmlns.com/foaf/0.1/" }, "@id": "http://me.markus-lanthaler.com/", "@type": [ "schema:Person", "foaf:Person" ] } ``` -------------------------------- ### Reference External Context Source: https://context7.com/w3c/json-ld-syntax/llms.txt Loads a context definition from a URL to promote reuse and reduce document size. ```json { "@context": "https://json-ld.org/contexts/person.jsonld", "name": "Manu Sporny", "homepage": "http://manu.sporny.org/", "image": "http://manu.sporny.org/images/manu.png" } ``` -------------------------------- ### Represent lists as arrays Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates simplifying @list structures into standard JSON arrays. ```json { "http://example.org/items": { "@list": [ "a", "b", "c" ] } } ``` ```json { "@context": { "items": { "@id": "http://example.org/items", "@container": "@list" } } } ``` ```json { "@context": { "items": { "@id": "http://example.org/items", "@container": "@list" } }, "items": [ "a", "b", "c" ] } ``` -------------------------------- ### Referencing External Resources Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates how to describe relationships between resources, including referencing external resources using their IRIs. This is fundamental to Linked Data principles. ```json { "@context": { "foaf": "http://xmlns.com/foaf/0.1/" }, "@id": "http://manu.sporny.org/about#manu", "foaf:name": "Manu Sporny", "foaf:knows": { "@id": "https://greggkellogg.net/foaf#me" } } ``` -------------------------------- ### Representing Singular Values as Arrays Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates how to force all property values to be represented as arrays, even if there's only one, using "@container": "@set". ```json { "@context": { "label": { "@container": "@set" } }, "@id": "http://example.com/person/1", "label": "Person" } ``` -------------------------------- ### Set Default Vocabulary with @vocab Source: https://context7.com/w3c/json-ld-syntax/llms.txt Defines a base IRI prefix for all terms not explicitly mapped in the context. ```json { "@context": { "@vocab": "http://xmlns.com/foaf/0.1/" }, "@type": "Person", "name": "Manu Sporny", "knows": { "@id": "https://greggkellogg.net/foaf#me", "@type": "Person", "name": "Gregg Kellogg" } } ``` -------------------------------- ### Using a Term as a Prefix with "@prefix": true Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Enables a term to be used as a prefix for compact IRIs when its `@id` does not end in a gen-delim character. Requires explicit setting of `"@prefix": true`. ```json { "@context": { "propertyOne": { "@id": "http://example.com/vocab/propertyOne", "@prefix": true } } } ``` -------------------------------- ### JSON-LD Context for Unordered Sets Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates using '@set' in the JSON-LD context to explicitly define a property's values as an unordered set, ensuring they are always represented as arrays. ```json { "@context": { "@vocab": "http://example.org/people#", "foaf": "http://xmlns.com/foaf/0.1/", "foaf:nick": {"@container": "@set"} }, "@id": "http://example.org/people#joebob", "foaf:nick": [ "joe", "bob", "jaybee" ] } ``` -------------------------------- ### Create Ordered Lists with @list Source: https://context7.com/w3c/json-ld-syntax/llms.txt Preserves the sequence of values in the RDF representation by wrapping them in a list container. ```json { "@context": {"foaf": "http://xmlns.com/foaf/0.1/"}, "@id": "http://example.org/people#joebob", "foaf:nick": { "@list": [ "joe", "bob", "jaybee" ] } } ``` -------------------------------- ### Turtle output for top-level @graph Source: https://github.com/w3c/json-ld-syntax/wiki/Rethinking-datasets-and-graphs? The resulting RDF graph representation in Turtle format. ```turtle ... . ... . ``` -------------------------------- ### JavaScript Access to Indexed Data Source: https://github.com/w3c/json-ld-syntax/blob/main/index.html Demonstrates how to access indexed data in JavaScript using the object's properties. This is useful when data is structured with an index map for efficient retrieval. ```javascript obj.athletes.pitcher ```