You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I saw that this library is using JSON2 instead of the standard JSON library. This library hasn't seen updates in the last 9 months (in fact, the author seems to have moved into doing JSON3 and it doesn't seem to respect the JSON standard.
Here there are a couple examples of JSON2 failing at a roundtrip:
I forked the package and ran into a couple of issues:
There is a clash while defining JSON as a type, as the module is also called JSON now, instead of JSON2. I temporarily solved it by renaming it as asJSON.
functionindex(c::WelcomeController)
render(asJSON, "Hello World")
end
Not as nice as before :/ But since Julia doesn't seem to admit aliasing imports I couldn't find a nicer workaround. Dispatching on a Symbol instead of the type and then adding a function that deal with each case would solve it, I suppose.
functionindex(c::WelcomeController)
render(:JSON, "Hello World")
end
The issue with that is that the wrong behaviour is still present in JSON3. I will open an issue in that repository. It was an open issue on the older package as well
I am not sure how experimental is it. Standard JSON is probably more batttle tested.
JSON doesn't have any concept of Tuples, and therefore it can be just parse back as a Pair or Dictionary. This test is relying on JSON2 "clever" conversions.
Which throws HTTP.IOExtras.IOError because it fails at parsing the IOBuffer
functionparse(::Type{MergedJSON}, buf::IOBuffer)::Vector{Pair{String,Any}}
nt = JSON.parse(buf) # fails herereturn [Pair(string(k),v) for (k,v) inpairs(nt)]
end
Perhaps it was also relying on some non-standard JSON2 behaviour? All other 155 tests are passing.
Shall I make a pull request or do you think these changes might be too disruptive?
when parse JSON object, JSON2.jl returns NamedTuple (not Dict), that is sometimes useful like indexing by . (dot).
that's for JSON.jl indexing by dot for Dict{String}
Activity
wookay commentedon Jan 17, 2020
I can't remember clearly, maybe JSON2 0.1.3 was better than JSON 0.16.1.
I'd like to using
JSON.PR's are welcome!
Amval commentedon Jan 17, 2020
Thank you for the quick response!
I forked the package and ran into a couple of issues:
JSONas a type, as the module is also calledJSONnow, instead ofJSON2. I temporarily solved it by renaming it asasJSON.Not as nice as before :/ But since Julia doesn't seem to admit aliasing imports I couldn't find a nicer workaround. Dispatching on a Symbol instead of the type and then adding a function that deal with each case would solve it, I suppose.
You can take a look here: https://github.com/Amval/Bukdu.jl
Stacktrace:
Amval commentedon Jan 17, 2020
Additionally, this method can probably be simplified from:
ntshould now be a dictionary, by removingpairs()the behaviour seems identical.wookay commentedon Jan 17, 2020
hmm.
JSON.parsereturnsDictJSON2.readreturnsNamedTupleJSON3.readreturnsJSON3.ObjectCan we use
JSON3?Amval commentedon Jan 17, 2020
The issue with that is that the wrong behaviour is still present in
JSON3. I will open an issue in that repository. It was an open issue on the older package as wellI am not sure how experimental is it. Standard JSON is probably more batttle tested.
Amval commentedon Jan 20, 2020
Ok, so I took another look and it was very easy to preserve your external API (so no external changes needed).
I got all tests passing except for two:
JSON doesn't have any concept of Tuples, and therefore it can be just parse back as a Pair or Dictionary. This test is relying on
JSON2"clever" conversions.And the one I mentioned before:
# @test_throws HTTP.ExceptionRequest.StatusError HTTP.post("http://127.0.0.1:8190/", ["Content-Type"=>"application/json"]; body=JSON.json(3))Which throws
HTTP.IOExtras.IOErrorbecause it fails at parsing theIOBufferPerhaps it was also relying on some non-standard
JSON2behaviour? All other 155 tests are passing.Shall I make a pull request or do you think these changes might be too disruptive?
wookay commentedon Jan 20, 2020
the problem is when
JSON.parsewithIOBuffer("3")compare to the others
Amval commentedon Jan 20, 2020
After reading the documentation, this solves the issue:
I made a PR. Thank you for your time and quick responses. Let me know if there's something I can help with :)
wookay commentedon Jan 20, 2020
thanks for your passionate contribution!
wookay commentedon Jan 20, 2020
providing namedtuple like Dict{String} also useful.
Amval commentedon Jan 20, 2020
I am not sure I understand what do you mean with the last message.
wookay commentedon Jan 20, 2020
when parse JSON object,
JSON2.jlreturns NamedTuple (not Dict), that is sometimes useful like indexing by.(dot).that's for
JSON.jlindexing by dot forDict{String}Amval commentedon Jan 20, 2020
Ah, I see. So is there something else I should do for the Pull Request to be accepted? :)
wookay commentedon Jan 20, 2020
I have commented 2 things in that PR. thanks.
Amval commentedon Jan 21, 2020
Alright. I incorporated the changes and now all checks are passing. Thank you for the support.
haydenfree commentedon Jan 23, 2020
@Amval Thanks for your work updating the package to remove JSON2.
@wookay Any idea when this change will be released in the next version?
wookay commentedon Jan 24, 2020
@haydenfree released it today. thanks!