We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I've noticed that as_json nests all the keys that are included in to_json under data, and the keys are in a different order. For example:
as_json
to_json
data
(byebug) manifest.to_json "{\"@context\":\"http://iiif.io/api/presentation/2/context.json\",\"@id\":\"http://localhost:3000/iiif/collection/gq67jr29s.json\",\"@type\":\"sc:Collection\",\"label\":\"t\",\"description\":\"t\"}" (byebug) manifest.as_json {"data"=>{"@id"=>"http://localhost:3000/iiif/collection/gq67jr29s.json", "label"=>"t", "description"=>"t", "@type"=>"sc:Collection", "@context"=>"http://iiif.io/api/presentation/2/context.json"}} (byebug)
Usually as_json returns a hash respresentation which is then used in to_json, for example:
(byebug) User.first.as_json.to_json == User.first.to_json true (byebug) manifest.as_json.to_json == manifest.to_json false
Since the keys are in a different order under data, re-parsing is the only way to get an equal result
(byebug) manifest.as_json["data"].to_json == manifest.to_json false (byebug) JSON.parse(manifest.as_json["data"].to_json) == JSON.parse(manifest.to_json) true
Would it make sense to patch this so that as_json returns a hash representation that would in turn be used for to_json?
I realize that I could use something like this to monkey patch it
def as_json JSON.parse(self.to_json) end
but it wouldn't be very efficient, and I thought it might make sense to change it here instead of opening up the class when I'm usign it?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I've noticed that
as_json
nests all the keys that are included into_json
underdata
, and the keys are in a different order. For example:Usually
as_json
returns a hash respresentation which is then used into_json
, for example:Since the keys are in a different order under
data
, re-parsing is the only way to get an equal resultWould it make sense to patch this so that
as_json
returns a hash representation that would in turn be used forto_json
?I realize that I could use something like this to monkey patch it
but it wouldn't be very efficient, and I thought it might make sense to change it here instead of opening up the class when I'm usign it?
The text was updated successfully, but these errors were encountered: