Uploaded image for project: 'data.json'
  1. DJSON-20

data.json reads and writes invalid JSON


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Labels:
    • Environment:

      Clojure 1.6 (et. al. I'm assuming)


      data.json silently reads and writes invalid JSON which pushes error checking out to consumers.

      http://www.json.org/ states that JSON must be an object or an array composed of values. http://jsonlint.com/ follows this pattern.

      > (json/write-str 1)
      > (json/write-str nil)
      > (json/write-str "charnock")

      Putting any of the above into http://jsonlint.com/ results in an error because jsonlint at least interprets the grammar to necessitate top level values being objects or arrays.

      Sadly, Chrome at least seems to do the same thing that data.json is doing here, which I've come to understand as 'non-strict JSON'. I think at the very least, it would be helpful to provide a 'strict' option, as apparently aeson (the Haskell JSON library) does, to pick your poison. I do think it would make sense to default to strict though, as that should be the most widely consumable format, and to then make the choice to drop to non-strict if you're cool with making that contract with all your consumers.

      I'm really not sure whether this is a bug or not. Probably more of an enhancement, especially since Chrome at least seems willing to parse each of the above. I'm thinking though of other clients that were written like jsonlint was to assume that JSON is always an object or array at the top level.




            • Assignee:
              stuart.sierra Stuart Sierra
              timvisher Tim Visher
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: