Sunday, December 04, 2011

JSON-C YouTube API

Developer's Guide: JSON-C / JavaScript - YouTube APIs and Tools - Google Code

YouTube site has not only a very rich content,
but also a very powerful set of APIs!

Besides very popular and standardized "ATOM" (XML) REST API,
there are also JSON and JSON-C ("C" stands for "Compact", most likely).
While there is no much "talk" about "JSON-C" to be found by googling,
the format does appear to be much more efficient for storage: good engineering, YouTube!

In addition to much smaller size (= less time to process), it makes programming simpler!

Comparing JSON and JSON-C

  • JSON-C feeds can exclude duplicate, irrelevant or easily calculated values.
  • do not preserve XML namespaces or schema information
  • minimize the number of JSON objects that are created in favor of simple properties


    Atom (XML):
    <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat'
      term='Sports' label='Sports'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='dog'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='catch'/>
    
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='frisbee'/>
    ...
    <media:group>
      <media:category label='Sports'
        scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Sports</media:category>
      <media:keywords>dog, catch, frisbee</media:keywords>
      ...
    
    <media:group>
    
    JSON: "category":[ {"scheme":"http://gdata.youtube.com/schemas/2007/categories.cat", "term":"Sports", "label":"Sports"}, {"scheme":"http://gdata.youtube.com/schemas/2007/keywords.cat", "term":"dog"}, {"scheme":"http://gdata.youtube.com/schemas/2007/keywords.cat", "term":"catch"}, {"scheme":"http://gdata.youtube.com/schemas/2007/keywords.cat", "term":"frisbee"} ], "media$group": { "media$category":[{"$t":"Sports", "label":"Sports", "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"], "media$keywords":{"$t":"dog, catch, frisbee"} }
    JSON-C: "category":"Sports", "tags":["dog", "catch", "frisbee"]

  • No comments: