2
http://domain.com/action?params[]=1&params[]=2&params[]=3

returns:

query: { 'params[]': [ '1', '2', '3' ] }

params[] as name instead of params?

After PHP it's kinda surprise.

jQuery serialization is adding [] on parameters btw.

Are you guys wrote a helper for this or I'm just doing it wrong?

2 Answers 2

3

This seems like expected behavior to me; I would be more surprised if the querystring parser removed part of the name. That is, the module is doing exactly what I would expect from a parser which simply splits name/value pairs by '&' and name/value by '=' (and unescapes special characters).

var qs = require('querystring');

qs.parse('params=1&params=2&params=3'); // Name should be "params"
// => { 'params': ['1', '2', '3'] }

qs.parse('params[]=1&params[]=2&params[]=3'); // Name should be "params[]"
// => { 'params[]': ['1', '2', '3'] }
Sign up to request clarification or add additional context in comments.

3 Comments

Mate i'm using jQuery and params serialization is taken by it. It's sending this params[]=1&params[]=2&params[]=3 type of query.
I have found a module for this. Question is closed. :)
A little observation is that, naturally, if you pass only one parameter using params=1 it will not be parsed as an array.
2

This module does parsing as required:

https://github.com/visionmedia/node-querystring

There is another one for complex arrays if this doesn't work:

https://github.com/jazzychad/querystring.node.js

Both found here: https://github.com/joyent/node/wiki/modules

3 Comments

Yes indeed. The default Node.js decided not to implement the feature for params with multiple values, but TJ's module solves that.
Guess Ry shouldn't be bothered with such misc issues atm.
Yeah probably it's ok to leave this out of the core and into a separate module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.