Skip to content

Instantly share code, notes, and snippets.

@veganstraightedge
Last active May 27, 2018 15:15
Show Gist options
  • Save veganstraightedge/6179849 to your computer and use it in GitHub Desktop.
Save veganstraightedge/6179849 to your computer and use it in GitHub Desktop.
http://json-ld.org claims to be a format of JSON to organize and link data on the web. HTML already provides a way to link data with the <a href> tag and microformats (in this case h-card and xfn) already provide a way to add additional machine readable semantics.
{
"@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"
}
<div class="h-card">
<a href="http://dbpedia.org/resource/John_Lennon" class="u-url u-uid p-name">John Lennon</a>
was born on
<time class="dt-bday" datetime="1940-10-09">October 9<sup>th</sup>, 1940</time>
and was married to
<a rel="spouse" href="http://dbpedia.org/resource/Cynthia_Lennon">Cynthia Lennon</a>.
</div>
<div class="h-card">
<a href="http://dbpedia.org/resource/John_Lennon" class="u-url u-uid p-name">John Lennon</a>
<time class="dt-bday">1940-10-09</time>
<a rel="spouse" href="http://dbpedia.org/resource/Cynthia_Lennon">Cynthia Lennon</a>
</div>
@Earthman
Copy link

Earthman commented Aug 7, 2013

Very nice, but you should probably add

Yoko Ono

:)

@msporny
Copy link

msporny commented Aug 8, 2013

Comparing against RDFa is also helpful:

<div vocab="http://schema.org/" 
  about="http://dbpedia.org/resource/John_Lennon" typeof="Person">
  <span property="name">John Lennon</span>  was born on
  <time property="born" datetime="1940-10-09">October 9<sup>th</sup>, 1940</time>
  and was married to
  <a rel="spouse" href="http://dbpedia.org/resource/Cynthia_Lennon">Cynthia Lennon</a>.
</div>

For fun, take the HTML markup above and dump it into http://rdfa.info/play/ to visualize the data.

@msporny
Copy link

msporny commented Aug 8, 2013

HTML already provides a way to link data with the A-HREF tag and microformats (in this case h-card and xfn) already provide a way to add additional machine readable semantics.

I think you might be missing the point of JSON-LD... it's meant to be used primarily for REST Web APIs and storing Linked Data in document-based storage engines. Sending HTML back and forth to do your REST Web API calls or storing HTML in a database as your primary data format isn't the best way to go about exchanging Linked Data. :)

@veganstraightedge
Copy link
Author

@msporny "isn't the best way" doesn't count as a good argument. Try again. ;)

@LeifW
Copy link

LeifW commented Aug 10, 2013

JSON is a common data format. The data parsed from Microformats 2 is described in terms of its JSON representation: http://microformats.org/wiki/microformats-2-parsing. Data is transformed between a variety of representations all the time - such as for this web page you're now reading, which is generated by interpolating the appropriate data from a database into the HTML. If people want a JSON view of my data without the HTML that they can use their JSON parsers / databases on, I don't see the harm in accommodating them.

You can see an example of this in action on e.g. http://calagator.org/events/1250464699, where the same data is available in microformats, microdata, JSON, and XML formats, or on my home page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment