JuliaLang/JSON.jl — pull request #58 by kmsquire (2014-04-16 21:03:24+00:00)
Title: Added default ordering using OrderedDicts

By convention, JSON objects are ordered. This PR uses OrderedDicts to achieve that, and sets it to the default:

```julia
julia> import JSON

julia> require("JSON/test/json_samples")

julia> println(a)
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}

julia> p = JSON.parse(a)
["menu"=>["id"=>"file","value"=>"File","popup"=>["menuitem"=>{["value"=>"New","onclick"=>"CreateNewDoc()"],["value"=>"Open","onclick"=>"OpenDoc()"],["value"=>"Close","onclick"=>"CloseDoc()"]}]]]

julia> typeof(p)
OrderedDict{String,Any} (constructor with 3 methods)

julia> replace(a, r"[\n ]", "") == replace(JSON.json(p), r"[\n ]", "")
true
```

To parse without ordering, `ordered` can be passed as a kw argument:
```julia
julia> JSON.parse(a, ordered=false)
["menu"=>["popup"=>["menuitem"=>{["value"=>"New","onclick"=>"CreateNewDoc()"],["value"=>"Open","onclick"=>"OpenDoc()"],["value"=>"Close","onclick"=>"CloseDoc()"]}],"id"=>"file","value"=>"File"]]

julia> typeof(ans)
Dict{String,Any} (constructor with 2 methods)
```