qs module in bodyDecoder should support JSON arrays? #324

Closed
Marak opened this Issue Jul 17, 2011 · 6 comments

Comments

Projects
None yet
5 participants

Marak commented Jul 17, 2011

If I parse this string:

 users[0][name]=marak&users[1][name]=tj

I currently get:

 {"users":{"0":{"name":"marak"},"1":{"name":"tj"}}}

I'd like to get:

 {"users": [{"name":"marak"},{"name":"tj"}]}

Would you be willing to add this to the qs module?

tmpvar commented Jul 17, 2011

agreed, I'd expect the latter

Contributor

aredridel commented Jul 17, 2011

Post-parse, perhaps -- if an object has only numeric keys, convert to an array?

Hard to do in-parser since it depends on later context.

Marak commented Jul 17, 2011

I think coercing objects with numerical props to arrays post-parse is a possible solution, but the idea of having to run an additional traverse on my JSON object and performing all those casts seems like a lot of over-head...

Marak commented Jul 17, 2011

Related issue, couldnt find qs repo before:

visionmedia/node-querystring#14

Member

tj commented Jul 17, 2011

x-www-form-urlencoded is all kinds of fucked up, though I agree that's definitely reasonable to expect

Contributor

aredridel commented Jul 17, 2011

Yeah. People have imposed structure on x-www-form-urlencoded that isn't naturally there. It's not such a mess until people do, but that's widespread now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment