Replies: 1 comment 1 reply
-
This is expected. There's no way to differentiate between input = {"a"=>[{"name"=>"x"}, {"other"=>"y"}]}
input.each do |k, v|
input[k] = v.map.with_index{|x, i| [i.to_s, x]}.to_h
end
input
# => {"a"=>{'0'=>{"name"=>"x"}, '1'=>{"other"=>"y"}}}
query = Rack::Utils.build_nested_query(input)
# => "a[0][name]=x&a[1][other]=y"
output = Rack::Utils.parse_nested_query(query)
# => {"a"=>{"0"=>{"name"=>"x"}, "1"=>{"other"=>"y"}}}
output.each do |k, v|
output[k] = v.sort_by{|k,| k.to_i}.map(&:last)
end
output
# => {"a"=>[{"name"=>"x"}, {"other"=>"y"}]}
input = {"a"=>[{"name"=>"x", "other"=>"y"}]}
input.each do |k, v|
input[k] = v.map.with_index{|x, i| [i.to_s, x]}.to_h
end
input
# => {"a"=>{"0"=>{"name"=>"x", "other"=>"y"}}}
query = Rack::Utils.build_nested_query(input)
# => "a[0][name]=x&a[0][other]=y"
output = Rack::Utils.parse_nested_query(query)
# => {"a"=>{"0"=>{"name"=>"x", "other"=>"y"}}}
output.each do |k, v|
output[k] = v.sort_by{|k,| k.to_i}.map(&:last)
end
output
# => {"a"=>[{"name"=>"x", "other"=>"y"}]} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just realized the following:
So it looks like not every object/hash can be encoded as a query parameter.
I'm pretty sure this is a known fact and I'm not the first one realizing this. Is there some specification or rfc that was incomplete in this part?
Beta Was this translation helpful? Give feedback.
All reactions