[rest-practices] JSON style guidelines?

James Bowes jbowes at redhat.com
Fri May 21 14:46:23 UTC 2010


Hi all:

For Candlepin, our primary media type is JSON. We've been using
RESTEasy with Jettison, which does:
JAXB annotated object -> XML -> JSON
As such, we're really representing the XML mappings of our objects in
JSON, rather than the objects themselves. Jettison is doing this with
the BadgerFish mapping convention, so we get JSON like:
{
  "consumer" : {
    "name" : "my consumer",
    "facts" : {
      "entry" : [
        { "key" : "memory", "value" : 12345 },
        { "key" : "memory.free", "value" : 60 }
      ]
    }
  }
}

My feeling is that if you're using JSON, you want it to be as compact as
possible. To that end, I've been working on using Jackson instead, which
cuts out the XML middleman, giving us JSON like:
{
  "name" : "my consumer",
  "facts" : {
    "memory" : 12345,
    "memory.free" : 60
  }
}

The mapping of the "facts" hash is much nicer, but you do lose that
beginning "consumer" type hint. I was thinking we could add a
"type_hint" field inside the returned object instead, or just rely on
the client to know what type to expect based on the url they hit.

What is the opinion of the list? Is anyone aware of any gotchas with the
various JSON styles for autogenerating class representations?

Thanks,

-James
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/rest-practices/attachments/20100521/9a21af10/attachment.sig>


More information about the rest-practices mailing list