jcard

(Redirected from jCard)

Jump to: navigation, search

jCard 0.1

A jCard is a standardized representation of an hCard encoded in JSON.

Contents

Introduction

A jCard is a standardized representation of an hCard encoded in JSON. The primary aim of a jCard is to provide a standardized JSON output in Microformat parsers to allow for easier interchange and integration with other applications.

The term jCard was first coined by Jon Sykes und Jim Barraud of the MicroJSON project. The MicroJSON wiki was also the first to come up with a standard for this format. This standard however is incomplete and inconsistent in regards to property names and structure. The specification presented here is a completely new attempt at defining a standard representation and only borrows the name from the original jCard specification at MicroJSON.org.

The specification is considered a draft. Contents are subject to change. It is provided here for reference and a basis for discussion on the mailing list.

Format

Authoring rules

  <p class="note">You can e-mail me at <a class="email"
  href="mailto:me@example.com">me@example.com</a>.</p>
 // Correct
 {
   "note" : ["You can e-mail me at me@example.com."],
   "email" : [{ value: "me@example.com" }]
 }
 
 // Wrong
 {
   "note" : [{
     "value" : "You can e-mail me at me@example.com.",
     "email" : [{ value: "me@example.com" }]
   }]
 }
 // Correct
 "fn" : "John Doe",
 "uid" : "http://jdoe.example.com"
 
 // Wrong
 "fn" : { "value" : "John Doe" }
 "uid" : ["http://jdoe.example.com"]
 // Correct
 "nickname" : ["Rio Demonhog", "Gus Aspara"]
 // Correct
 "email" : [
   {"type" : ["pref"], "value" : "foo at example.com"},
   {"value" : "bar at example.com"}
 ]
 // Wrong
 "email" : [{"type" : "pref"}]

Open for Discussion

The following is still undecided and needs further discussion

 // Wrong
 "email" : "bar at example.com"
 
 // Correct
 "email" : [{"value" : "bar at example.com"}]
 // Wrong
 "email" : [{"value" : "bar at example.com"}]
 "nickname" : ["Gogo Fiasco"]
 // Correct
 "email" : "bar at example.com"
 "email" : [
   {"type" : ["pref"], "value" : "foo at example.com"},
   "foobar at example.com"
 ]
 "nickname" : "Gogo Fiasco"
 // Correct
 "email" : [{"value" : "bar at example.com"}]
 "email" : "bar at example.com"
 "email" : [
   {"type" : ["pref'], "value" : "foo at example.com"},
   "foobar at example.com"
 ]
 "nickname" : ["Gogo Fiasco"]
 "nickname" : "Gogo Fiasco"

Field and Element Details

[ This section is a placeholder and should be replaced with field descriptions ]

Implementations

The author of Optimus has announced his support of jCards.

A proof-of-concept jCard web service is available (powered by Cognition) at http://srv.buzzword.org.uk/jcard/. To use it, simply append the URL of an hCard page (minus the "http://"). e.g.

http://srv.buzzword.org.uk/jcard/www.example.com/contact.html

Javascript

For consistency with hCard, jCard retains hyphenated key names, such as "given-name". However, it has been remarked that for Javascript consumers, camel case terms such as givenName would be more useful, as they can be addressed as object properties rather than the keys of an associative array. The following Javascript function allows easy conversion from jCard's hyphenated key names to camel case, and back again. It is released into the public domain by its author, Toby Inkster.

/* camelObject ($object, $reverse)
 * Replaces hyphenated-keys in $object with camelCaseKeys.
 * Optional second argument specifies that the reverse should happen.
 * Not always round-trip safe, but good enough for jCard.
 */
function camelObject ($obj, $reverse)
{
	/* Would be nice to just use regular expressions, but callbacks fail in
	 * all released versions of Safari so far (fixed in WebKit nightlies
	 * apparently).
	 */
	function cc ($str, $reverse)
	{
		if ($reverse)
		{
			var $rv = '';
			for (var $i=0; $str[$i]; $i++)
			{
				if ($str[$i] == $str[$i].toUpperCase()) $rv += '-';
				$rv += $str[$i];
			}
			return $rv.toLowerCase();
		}
		
		var $chunks = $str.split('-');
		var $rv = $chunks[0];
		for (var $i=1; $chunks[$i]; $i++)
			$rv += $chunks[$i].charAt(0).toUpperCase() + $chunks[$i].substring(1);
		return $rv;
	}

	if (typeof $obj == 'object' && $obj instanceof Array)
	{
		var $rv = new Array;
		for (var $i in $obj)
			$rv[$i] = camelObject($obj[$i], $reverse);
		return $rv;
	}
	
	else if (typeof $obj == 'object')
	{
		var $rv = new Object;
		for (var $key in $obj)
			$rv[cc($key, $reverse)] = camelObject($obj[$key], $reverse);
		return $rv;
	}
	
	return $obj;
}

/*
USAGE:

var jCard = {
  "fn" : "Toby Inkster",
  "n" : {
    "given-name" : ["Toby"],
    "family-name" : ["Inkster"]
  }
}
var camelCard = camelObject(jCard);
camelCard.n.additionalName[0] = "Andrew";
var jCardNew = camelObject(camelCard, true);

*/

Criticism

Critics argued, that there is no need for a jCard standard. In order to preserve the semantics of microformats, the entire marked up HTML or the URI should be passed between applications. Applications should then decide by themselves on how to represent a Microformat internally.

References

jcard was last modified: Wednesday, December 17th, 2008

Views