This page explores the idea of transliterating JSON-LD into YAML syntax, yielding YAML-LD (YAML for Linked Data).


JSON and YAML have very different concrete syntax (ie, encoding, representation, serialization format), but their abstract syntax is pretty much identical (trees, composed of hashes, lists, and scalars). So, it is very easy to transliterate higher-level idioms such as JSON-LD into YAML syntax. The resulting format has YAML's clarity and JSON-LD's semantics:

  • unambiguous references, via URIs

  • context, data types, macros, properties, terms, ...

For more information, see JSON-LD's Introductory Material, eg:

Example 1

To see how YAML-LD might look, let's adapt a small example from the JSON-LD web site. Here is the example, in nicely-formatted JSON-LD:

  "@context": "http://json-ld.org/contexts/person.jsonld",
  "@id":      "http://dbpedia.org/resource/John_Lennon",
  "name":     "John Lennon",
  "born":     "1940-10-09",
  "spouse":   "http://dbpedia.org/resource/Cynthia_Lennon"

Here, for comparison, is the equivalent YAML-LD:

  "@context":  http://json-ld.org/contexts/person.jsonld
  "@id":       http://dbpedia.org/resource/John_Lennon
  name:        John Lennon
  born:        1940-10-09
  spouse:      http://dbpedia.org/resource/Cynthia_Lennon

Note: The current YAML specification reserves the at sign (@) for future use. So, although some YAML parsers will accept (and autoquote) keys and values that contain at signs, explicit quoting is advisable.

JSON-LD Interpretation

The JSON-LD Playground will show us several versions of this information. The Expanded version shows off the Linked Data aspect:

    "@id": "http://dbpedia.org/resource/John_Lennon",
    "http://schema.org/birthDate": [
        "@type": "http://www.w3.org/2001/XMLSchema#dateTime",
        "@value": "1940-10-09"
    "http://xmlns.com/foaf/0.1/name": [
        "@value": "John Lennon"
    "http://schema.org/spouse": [
        "@id": "http://dbpedia.org/resource/Cynthia_Lennon"

JS-YAML Interpretation

The JS-YAML demo (a JavaScript parser for YAML) has no notion of Linked Data, so we lose the rich contextual information but pick up some automagical data type transformations:

  '@context': 'http://json-ld.org/contexts/person.jsonld',
  '@id':      'http://dbpedia.org/resource/John_Lennon',
  name:       'John Lennon',
  born: {
    Wed, 09 Oct 1940 00:00:00 GMT
    constructor: {
      [Function: Date],
      now:    [Function now],
      UTC:    [Function UTC],
      parse:  [Function: parse]
  } },
  spouse:     'http://dbpedia.org/resource/Cynthia_Lennon'

Example 2

The JSON-LD page in Wikipedia shows off some RDF-friendly usage:

  "@context": {
    "name":      "http://xmlns.com/foaf/0.1/name",
    "homepage": {
      "@id":     "http://xmlns.com/foaf/0.1/workplaceHomepage",
      "@type":   "@id"
    "Person":    "http://xmlns.com/foaf/0.1/Person"
  "@id":         "http://me.markus-lanthaler.com",
  "@type":       "Person",
  "name":        "Markus Lanthaler",
  "homepage":    "http://www.tugraz.at/"

Here is the same example, in YAML-LD:

    name:         http://xmlns.com/foaf/0.1/name
      "@id":      http://xmlns.com/foaf/0.1/workplaceHomepage
      "@type":    "@id"
    Person:       http://xmlns.com/foaf/0.1/Person
  "@id":          http://me.markus-lanthaler.com
  "@type":        Person
  name:           Markus Lanthaler
  homepage:       http://www.tugraz.at/

Here, taken again from the JSON-LD playground, is the Expansion:

    "@id": "http://me.markus-lanthaler.com",
    "@type": [
    "http://xmlns.com/foaf/0.1/workplaceHomepage": [
        "@id": "http://www.tugraz.at/"
    "http://xmlns.com/foaf/0.1/name": [
        "@value": "Markus Lanthaler"

This wiki web is maintained by Rich Morin. Please feel free to email comments, suggestions, etc!

Topic revision: r6 - 29 Mar 2014, UnknownUser
Guest Access
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback