Daniel Doubrovkine bio photo

Daniel Doubrovkine

aka dB., CTO at artsy.net, fun at playplay.io, NYC

Email Twitter LinkedIn Github

I found this quite unusual. I needed to receive an array with some nested hashes part of a query string into a JSON API. Passing encoded JSON wasn’t looking hot. Turns out, in Rails, this can be done with the [] syntax.

/stuff?widget[]=first-widget&gadget[]=a-gadget&widget[]=another%20widget

What the heck is this [] syntax?! Why is there multiple widget entries?! There’re a few good articles on this, including this one. Web developers apparently have been doing this forever. I am far behind :(

Here’s what Rails parses from this query string.

{
    :widget => ["first-widget",  "another widget"],
    :gadget => ["a-gadget"]
}

Awesome.