Skip to content

Return a more uniform structure in as_json #151

@linkyndy

Description

@linkyndy

At the moment, results are returned as a regular hash, with keys and values containing a mix of strings and symbols:

{"nature"=>:archive, "intrinsics"=>nil, "entries"=>[{:type=>:file, :size=>53335, :filename=>"foo"}, {:type=>:file, :size=>292210, :filename=>"bar"}, {:type=>:file, :size=>1965044, :filename=>"baz"}], "format"=>:zip}

It happened to me several times that I was getting the key or comparing the value using the wrong type. I think normalising the return value of as_json would be a nice improvement.

Currently, I am doing this to normalise the result hash:

JSON.load(JSON.dump(result))

Here are the options I see:

  • use strings or symbols for all key/values (since this is meant to serialise to JSON at some point, it might make sense to stick to strings)
  • use a hash with indifferent access; however, that likely adds a dependency and diverts from the idea of having a very strict contract and the least number of dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions