Hypermedia and JSON?

by Subbu Allamaraju on April 25, 2008 · 6 comments

Mike Amundsen is wondering how to express hypermedia in JSON. He rightly identifies that there needs to be a new media type, e.g. application/hypermedia+json. Putting together such a new media type is not hard, but in my view, the real issue is defining a JSON format that can express data/media as well as hypermedia. One possibility is to take the "payload" formats defined by Atom and Atom Publishing Protocol, and translate that into JSON using some simple rules. Here is one, based on example from RFC 5023.

{
"entry" : {
"title" : Atom-Powered Robots Run Amok",
"id" : "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a",
"updated" : "2003-12-13T18:30:02Z",
"author" : {
"name" : "John Doe"
},
"content": "Some text.",
"link" : {
"rel" : "edit",
"href" : "http://example.org/edit/first-post.atom"
}
}

{ 6 comments… read them below or add one }

Patrick Logan April 25, 2008 at 2:40 pm

Yeah, I’m not sure we should pile too much on little JSON’s back. JSON is merely a simple data structure serialization format.

My fear is that this is notion of links is at the top of a slippery slope that tries to define a big spec. The inclusion of links in JSON should be by convention. If a certain convention is widely used, fine. But that’s not JSON, that’s one conventional use of JSON.

Reply

Subbu Allamaraju April 25, 2008 at 5:42 pm

Right. My goal was to inject some hypermedia in a representation in some media type. I am not proposing that Atom be used as a *the* format for all media types, but it gives some ideas on what kinds of things are needed to be useful as hypermedia in a representation.

Reply

David Lojudice Sobrinho May 19, 2010 at 11:21 am

Json hypermedia? Duck typing: does it have HREF and TYPE? Quack! it is a link!

“self”:{“href”:”http://server/2293823″, “type”:”application/json”}

Reply

Subbu Allamaraju May 19, 2010 at 11:50 am

Good point, and the answer is “it depends”. See Recipe 5.2 (http://my.safaribooksonline.com/9780596809140/recipe-how-to-use-links-in-json) of the RESTful Web Services Cookbook for an alternative style.

Reply

savaş oyunları June 11, 2011 at 2:02 am

Very nice thanks a sharing.. perfect..

Reply

gino pilotino August 9, 2011 at 2:19 am

interesting, i’ve thought about a json-only atom publishing protocol equivalent as well

Reply

Leave a Comment

Previous post:

Next post: