https://www.npmjs.com/package/qs
Usage
Parsing Objects
qs allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets []
. For example, the string 'foo[bar]=baz'
converts to:
Parsing Arrays
qs can also parse arrays using a similar []
notation:
Stringifying
When stringifying, qs by default URI encodes output. Objects are stringified as you would expect:
This encoding can be disabled by setting the encode
option to false
:
Handling of null
values
By default, null
values are treated like empty strings:
Dealing with special character sets
By default the encoding and decoding of characters is done in utf-8
. If you wish to encode querystrings to a different character set (i.e. Shift JIS) you can use the qs-iconv
library:
RFC 3986 and RFC 1738 space encoding
RFC3986 used as default option and encodes ' ' to %20 which is backward compatible. In the same time, output can be stringified as per RFC1738 with ' ' equal to '+'.
assert.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c');
assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c');