Javascript Object Notation for Linked Data: Understanding JSON-LD in 10 points

Through our SEO Agency Optimize 360

Javascript Object Notation for Linked Data (JSON-LD)


Le JavaScript Object Notation for Linked Data (JSON-LD) is a widely used data format for structuring information on the web.

This article presents JSON-LD in ten main points, to help you better understand its features and how it can be used in your projects.

JSON-LD

1. What is JSON-LD?

As its name suggests, JSON-LD is an extension of the well-known JSON format. It was designed to simplify the use of structured data on the web, enabling developers to include semantic data directly in their documents HTML. JSON-LD is based on JSON syntax, which means it is easy to read and write for both humans and machines.

2. Why choose JSON-LD?

There are a number of structured data formats available, but JSON-LD offers some key advantages that set it apart from the rest:

  • Interoperability : JSON-LD uses a standardised vocabulary based on World Wide Web Consortium (W3C), guaranteeing greater compatibility between different applications and platforms.
  • Flexibility : Thanks to its simple, lightweight syntax, JSON-LD can be easily integrated into HTML, JavaScript or other programming languages.
  • Ease of use : The ease with which JSON can be read and written makes JSON-LD more accessible to developers than other structured data formats such as RDF/XML.

3. The main elements of JSON-LD

JSON-LD is made up of several key elements that define the structure of the data and its meaning:

  1. @context : This element maps the attribute names used in the JSON-LD to IRIs (Internationalized Resource Identifiers) in order to guarantee a unique interpretation of the data across the semantic web.
  2. @type : It defines the class (or type) of the object described, making it possible to specify the nature of the data contained in the JSON-LD document.
  3. @id : As its name suggests, this element assigns a unique identity to a JSON-LD object within a document. The identifier must be an IRI to guarantee data interoperability.
  4. @value : Allows you to assign a literal value to a property, without having to create a new JSON-LD object.
  5. @language : This keyword is used to define the language of a character string, following the BCP47 codes.

4. JSON-LD data types

JSON-LD supports different types of data to represent textual, numerical, Boolean or spatial information. Here are a few examples:

  • String (text) : represented by double inverted commas (e.g. "Hello World!").
  • Number : can be whole numbers or decimals, without inverted commas (e.g. 42, 3.14).
  • Boolean (true or false) : represented by the literal values "true" and "false" (without inverted commas).
  • Object : made up of a set of key-value pairs enclosed in braces (e.g. {"name": "John", "age": 30}).
  • Array : an ordered set of values in square brackets (e.g. [1, 2, 3]).

5. Relationship modelling with JSON-LD

JSON-LD objects can be associated with each other via properties, forming a graph structure. For example, an "author" relationship between a book and its author can be modelled as follows:


{
  "@context" : "http://schema.org/",
  "@type" : "Book",
  "title": "Les Misérables",
  "author" : {
    "@type" : "Person",
    "name" : "Victor Hugo"
  }
}

6. Using existing vocabularies with JSON-LD

To ensure data interoperability, it is recommended to use standardised vocabularies such as Schema.org or Dublin Core in JSON-LD documents. This enables data consumers (search engines, web applications, etc.) to better understand and exploit the information contained in your document.

Here is an example of using Schema.org vocabulary to describe a recipe:


{
  "@context" : "http://schema.org/",
  "@type" : "Recipe",
  "name" : "Tiramisu",
  "ingredients" : [
    "4 eggs",
    "500 g mascarpone cheese,
    "150 g sugar,
    "24 sponge biscuits,
    "Black coffee
  ],
  "image": "http://exemple.com/tiramisu.jpg",
  "prepTime": "PT30M",
  "cookTime" : "0"
}

7. The benefits of JSON-LD for SEO

By injecting structured JSON-LD data into your web pages, you can improve their visibility and accessibility for search engines. The main platforms (Google, Bing, Yahoo !, Yandex) support JSON-LD syntax and can use this data to enrich their search results with additional information (" rich snippets ") such as star ratings, images, links to social profiles, etc.

8. Integrating JSON-LD into an HTML document

To add JSON-LD data to an HTML page, simply insert it in a <script> type application/ld+jsonusually placed in the header (<head>) of the document :


JSON-LD integration example
    
    {
      "@context" : "http://schema.org/",
      "@type" : "WebPage",
      "name" : "JSON-LD integration example,
      "url" : "http://exemple.com/integration-json-ld"
    }
    
  
  ...

9. Tools for working with JSON-LD

Several online tools and libraries are available to help you create, validate and manipulate JSON-LD documents. Here are a few examples:

  • JSON-LD Playground : An online editor for testing and viewing JSON-LD documents
  • Google Structured Data Testing Tool : A tool for validating and previewing structured data offered by Google.
  • JSON-LD Libraries : Libraries for manipulating and transforming JSON-LD using different programming languages (JavaScript, Python, Ruby, etc.).

10. Additional resources on JSON-LD

To find out more about JSON-LD and how to use it, here are some useful resources:

  • Official JSON-LD specification: JSON-LD technical documentation published by W3C
  • JSON-LD and Schema.org : A practical guide to using JSON-LD with the Schema.org vocabulary
  • Tutorials and code examples : Several sites offer tutorials, examples and tips for working with JSON-LD in various contexts and applications.
blank Digital Performance Accelerator for SMEs

ContactAppointments

en_GBEN