Last week jCard became rfc7095. jCard specifies a way to serialize the elusive vCard as Json.
I'm a big fan of this format. vCards have been around since 1995, and even though we've had a pretty significant update in 2011 in the form of vCard 4.0, the format is still complicated to parse, has a number of problems that go all the way back to the early days.
Worse, a lot of people don't really see the value of upgrading, and thus stick to using vCard 3. Or even 2.1 if you're microsoft.
The biggest problem with vCards, is that upon a first glance, the format seems extremely easy to parse and generate with just a couple of string manipulation functions. When you dig deeper into the specifications though, you'll notice that it's actually really complex and hosts a ton of edge cases.
The result of this, is that there are a ton of broken vCard generators in the wild, and even more broken vCards.
jCard should solve a lot of that. The serialization rules for json are really simple, and most programming languages ship with a correct implementation. Serializing vCards as json means that there's no longer a worry about things like escaping, new lines, and character encoding (it's UTF-8).
So I'm hoping that the benefits of jCard will be big enough for people to eventually abandon vCard altogether. The 'clean break' in the format, rather than a progressive update should help ensuring that all newly generated jCards are in a much better state than some of the vCards we're seeing.
Using it in PHP
sabre/vobject already has support for jCard for some time. To parse jCard:
<?php
$input = file_get_contents('jcard.json');
$jCard = Sabre\VObject\Reader::readJson($input, 'r');
?>
How it looks
Here's a sample of my vCard (generated by OS X Contacts.app, but significantly shortened).
BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//Mac OS X 10.9.1//EN
N:Pot;Evert;;;
FN:Evert Pot
EMAIL;type=INTERNET;type=HOME:evert@rooftopsolutions.nl
EMAIL;type=INTERNET;type=WORK:evert@fruux.com
TEL;type=CELL;type=VOICE:+1 647 471 2661
ADR;type=HOME:;;24 Settles Street;London;;E1 1JP;United Kingdom
NOTE:Foo
item2.URL;type=pref:http://evertpot.com/
BDAY:1985-04-07
X-JABBER;type=HOME;type=pref:evertpot@gmail.com
UID:35269e7016a018e3
END:VCARD
Convering it can be done so, if you have the vObject command line utility installed:
$ vobject convert --pretty input.vcf output.json
What follows is the output, pretty-printed. As you can see the output is a lot larger, and arguably less readable. This is also the one benefit the old mime-dir based format has, it's easy for a human to process.
[
"vcard",
[
[
"version",
{
},
"text",
"4.0"
],
[
"prodid",
{
},
"text",
"-\/\/Sabre\/\/Sabre VObject 3.1.3\/\/EN"
],
[
"n",
{
},
Truncated by Planet PHP, read more at the original (another 6429 bytes)
more
{ 0 comments... » jCard is now a thing read them below or add one }
Post a Comment