Mapping Atom to JSON
I've run into a few references to Atom - JSON mappings, but nothing really canonical yet. It seems that Google has a mapping out there that's really very XML-like, down to the XML declaration, which seems a bit much. On the positive side, they've taken steps to handle things like namespaces, which would certainly be very helpful in a general feed-conversion utility.
<feed xmlns="http://www.w3.org/2005/Atom">
<id>http://atomtests.philringnalda.com/tests/item/title/html-entity.atom</id>
<title>Atom item title html entity</title>
<updated>2005-12-18T00:13:00Z</updated>
<author>
<name>Phil Ringnalda</name>
<uri>http://weblog.philringnalda.com/</uri>
</author>
<link rel="self" href="http://atomtests.philringnalda.com/tests/item/title/html-entity.atom"/>
<entry>
<id>http://atomtests.philringnalda.com/tests/item/title/html-entity.atom/1</id>
<title type="html">&lt;title></title>
<updated>2005-12-18T00:13:00Z</updated>
<summary>An item with a type="html" title consisting of a less-than
character, the word 'title' and a greater-than character, where the
character entity reference for the less-than character is escaped by
replacing the ampersand with a character entity reference.</summary>
<link href="http://atomtests.philringnalda.com/alt/title-title.html"/>
<category term="item title"/>
</entry>
</feed>
I imagine that you could map this into JSON something like this:
{ "feed" : {
"id" : "http://atomtests.philringalda.com/tests/item/title/html-entity.atom",
"title" : "Atom item title html entity",
"updated" : "1134889980",
"author" : [{
"name" : "Phil Ringalda",
"uri" : "http://weblog.philringnalda.com/" }],
"link" : [{
"rel" : "self",
"href" : "http://atomtests.philringnalda.com/tests/item/title/html-entity.atom" }],
"entry" : [{
"id" : "http://atomtests.philringnalda.com/tests/item/title/html-entity.atom/1",
"updated" : "1134889980",
"title" :
{ "html" : "&lt;title>" },
"summary" : {
"text" : "An item with a type='html' title consisting of a less-than character, the word 'title' and a greater-tan character, where the character entity reference for the less-than character is escaped by replacing the ampersand with a character entity reference." },
"link" : [{
"rel": "alternate",
"href" : "http://atomtests.philringnalda.com/alt/title-title.html" }],
"category" : {
"term" : "item title" }
}]
}}
This is a bit different from Google's mapping, which is a straightforward mapping from attributes to members. In this case, it seems a little bit nicer to omit the type and just write a member out with the correct type, so you can write something like f.feed.entry[0].title.html (assuming you've assigned a var f to the structure defined above), rather than testing f.feed.entry[0].title.type.