Master URL query strings: learn how to serialize and parse arrays, handle nested objects, avoid duplicate keys, and properly percent-encode parameters.
Frequently Asked Questions
Q1. What is the best way to pass an array in a URL query string?
The three most common formats are: 1) Repeat keys: ?tags=js&tags=react, 2) Bracket syntax: ?tags[]=js&tags[]=react (popular in PHP, Rails, Express qs), and 3) Comma-separated: ?tags=js,react.
Q2. How do I serialize nested objects into query parameters?
Use bracket notation such as ?filter[status]=active&filter[author][name]=john. In Node.js or browser apps, the qs npm package parses these nested structures automatically.
Q3. Why does a plus sign (+) turn into a space in query strings?
In application/x-www-form-urlencoded media types, the plus sign (+) represents a space. If you want a literal plus sign, you must percent-encode it as %2B.