Skip to content

dak/json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Reasons to Use JSON

  1. JSON is more compact, meaning smaller file sizes to send to a client
  2. JSON is formal and precise, so there's less possibility of ambiguity or exceptions
  3. JSON is much faster to parse than XML, and you don't need to write any custom code to parse it
    1. Current code to parse a book (already broken with new COLLXML format, and code complexity increases exponentially with more features):

      parseHTML = (html) ->
        if typeof html isnt 'string' then return []
      
        results = []
      
        $(html).find('> ol').find('> li').each (index, el) ->
          $el = $(el)
          $node = $el.children().eq(0)
      
          if $node.is('a')
            id = $node.attr('href')
            title = $node.text()
      
          # Only remember the title if it's overridden
          if not title or $node.hasClass('autogenerated-text')
            results.push({id: id})
          else
            results.push({id: id, title: title})
      
        return results
      
    2. No code is required to parse JSON, since support is built-in to Backbone, but if you needed to, it would always be one line:

      1. JSON.parse(string) in JavaScript
      2. In Python, just import json and then json.loads(string)
  4. JSON, unlike XML, matches the data model of most programming languages
    1. Literally "JavaScript Object Notation", it can be serialized and parsed back into an object in any modern browser
    2. Maps easily to Python as well: Object = Dictionary, Array = List, etc.
  5. Support for JSON has only been growing as it is becoming the default data exchange format for the web
  6. PostgreSQL has built-in support for JSON, including automatic validation
    1. http://www.postgresql.org/docs/devel/static/datatype-json.html
    2. http://www.postgresql.org/docs/9.3/static/functions-json.html
  7. Backbone.js is designed to work with specifically with JSON
    1. "Backbone.js gives structure to web applications ... and connects it all to your existing API over a RESTful JSON interface."
  8. An XML or HTML markup of a book can be generated from data more easily and quickly than XML can be parsed into data
  9. A template (or multiple templates) could be used to easily convert data into any format, simplifying support for different formats. So, for example, we should be able to avoid restyling every book.
  10. Because of things like xincludes, XML must be parsed into data, manipulated, and then re-generated. Storing as JSON skips the first step, because it already is data.
  11. We're already using JSON. Currently, the XML/HTML is simply being served as a JSON field. Serving just JSON would simplify it to a single data format.
  12. Folders are already serving their contents as JSON.
  13. ATC is effectively just taking the HTML/XML being served currently and converting it into a JavaScript Object (JSON).

Releases

No releases published

Packages

No packages published