A search page needs to send several tags, a price range and a sort order in its URL. The front end builds ?tag=new&tag=sale&filter[price][max]=50, the backend receives only one tag, and the price filter arrives as a strangely named key instead of a nested object. Nothing is broken in the usual sense: the two sides simply follow different conventions.
Query strings are one of the oldest parts of the web, and they only define flat key=value pairs. Everything beyond that, including arrays, nested objects and types, is convention. This guide explains the main conventions, how common platforms read them, and how to convert query strings to JSON and back without surprises.
What the standard actually defines
The query string is the part of a URL after ?. The format browsers use for it, application/x-www-form-urlencoded, defines:
- pairs separated by
&; - keys and values separated by
=; - special characters percent-encoded (
%26for a literal&,%3Dfor=); - spaces encoded as
+, a legacy of HTML forms, while%20also works.
That is all. There are no arrays, no objects and no types: every value is a string. page=2 gives you the string "2", and active=true the string "true".
The four common conventions for arrays
Because the format is flat, frameworks invented ways to express lists. Here is the same list, tags: ["new", "sale"], in each style:
| Convention | Query string | Typical users |
|---|---|---|
| Brackets | tags[]=new&tags[]=sale |
PHP, Ruby on Rails, the qs library |
| Repeated keys | tags=new&tags=sale |
HTML forms with multi-selects, many Java and Python frameworks |
| Indices | tags[0]=new&tags[1]=sale |
qs with the indices option, some .NET binders |
| Comma-separated | tags=new,sale |
Many REST APIs, by their own documentation |
Nested objects use brackets as a path: filter[price][max]=50&filter[colour]=black means {"filter": {"price": {"max": "50"}, "colour": "black"}}. The bracket style for nesting originated in PHP and was adopted by Rails and the widely used qs library for Node.js.
None of these is "correct". The only rule that matters is that the sender and the receiver agree.
How platforms parse the same string
Take tag=new&tag=sale&filter[price][max]=50:
- PHP turns bracket keys into arrays in
$_GET, sofilterbecomes a nested array. Repeated keys without brackets overwrite each other:$_GET['tag']is just"sale". - Node.js with the
qslibrary gives{ tag: ["new", "sale"], filter: { price: { max: "50" } } }. Whether a framework such as Express usesqsor a simple flat parser depends on its version and settings, so check your framework's query parser configuration. - Browsers and Node.js
URLSearchParamskeep everything flat. Repeated keys are preserved, but you have to ask for them:
const p = new URLSearchParams("tag=new&tag=sale&filter[price][max]=50&q=desk+lamp");
p.getAll("tag"); // [ 'new', 'sale' ]
p.get("filter[price][max]"); // '50'
p.get("q"); // 'desk lamp'
Object.fromEntries(p); // { tag: 'sale', 'filter[price][max]': '50', q: 'desk lamp' }
The last line is a common bug. Object.fromEntries keeps only the last value of a repeated key, so the tag new silently disappears.
Convert a query string to JSON with our tool
The Query String Parser converts in both directions in your browser.
Query string to JSON
- Open the Query String Parser and set Direction to Query string → JSON.
- Paste a query string or a full URL into Query string or full URL, or click Load sample.
- Choose the options:
- Decode + as space treats
+as a space, as HTML forms do. Switch it off if a literal plus sign matters, for example in some tokens. - Nest a[b]=1 and a[]=1 builds nested objects and arrays from bracket keys. Off, keys like
filter[price][max]stay flat. - Convert numbers & booleans turns
"2"into2and"true"intotrue. Off by default, because a query string cannot tell you whether007was meant as a number.
- Decode + as space treats
- Read the JSON output. Repeated keys always become arrays.
With nesting on, ?q=desk+lamp&tag=new&tag=sale&filter[price][max]=50&page=2 becomes:
{
"q": "desk lamp",
"tag": ["new", "sale"],
"filter": { "price": { "max": "50" } },
"page": "2"
}
JSON to query string
- Set Direction to JSON → query string and paste a JSON object into JSON object.
- Pick the Array format:
a[]=1&a[]=2,a=1&a=2,a[0]=1&a[1]=2ora=1,2, whichever your backend expects. - Choose Encode spaces as + (or
%20when off) and whether to Percent-encode [ ]. Brackets are legal in most URLs as typed, but some strict servers and proxies want them encoded as%5Band%5D. - Copy the result and append it to your URL after
?.
Pitfalls and how to avoid them
Plus signs and spaces
In a query string, + means a space. A value that genuinely contains a plus sign, such as +44 20 7946 0000 or a Base64 token, must be encoded as %2B. If phone numbers or tokens arrive with spaces instead of plus signs, this is why. Use the URL Encoder/Decoder to encode single values correctly.
Comma-separated lists and commas in values
tags=new,sale is compact, but a value that contains a comma, such as "Smith, J.", becomes ambiguous. Prefer repeated keys or brackets for free-text values.
Types are always guesses
Every value in a query string is text. Convert types on the server based on what each parameter should be, rather than guessing from the look of the value. A product code 00123 must stay a string.
Empty values and missing values
?coupon= sends an empty string; leaving the parameter out sends nothing. Many backends treat them differently, so decide which one your API expects.
Length limits
URLs are not unlimited. Browsers, servers and proxies each impose maximum lengths, and they differ. For large or deeply nested filters, send JSON in a POST body instead.
Related tools
To see the whole URL, including host, path and fragment, with an editable parameter table, use the URL Parser. For campaign links, the UTM Builder creates properly encoded tracking parameters, and to inspect the JSON result further, the JSON Formatter pretty-prints it.
Frequently asked questions
How do I pass an array in a URL query string?
Use the convention your backend understands: brackets (tags[]=a&tags[]=b), repeated keys (tags=a&tags=b), indices or a comma-separated value. There is no universal standard, so check the API or framework documentation.
Is + or %20 correct for spaces in a query string?
Both are widely accepted in query strings; + comes from HTML form encoding. In the path part of a URL, only %20 means a space.
Why does my backend only see the last value of a repeated key?
Its parser maps each key to a single value, keeping the last one. Use the bracket style if the backend supports it, or read all values explicitly, for example with getAll().
Can a query string contain nested objects?
Not natively, but the bracket convention a[b][c]=1 is widely used to represent nesting. The receiving parser must support it for the structure to be rebuilt.
Are query parameter values case-sensitive?
The format itself preserves case exactly, so Sort=Price and sort=price are different keys and values. Whether the application treats them as equal is up to its code.