Use JavaScript’s built-in URLSearchParams API to parse a URL query string into decoded name/value pairs, and call getAll() when a parameter name may repeat.
URLSearchParams handles percent escapes and plus signs for you. For a complete URL, use its searchParams property rather than passing the entire address to the query-string parser.

Parse the query with URLSearchParams
Use this sequence whenever your input is either raw query data or an absolute address.
- Isolate the query text. URLSearchParams expects form-style query data, not a full address. If you have ?tag=js&tag=url, remove the question mark for clarity and pass tag=js&tag=url. If you have a complete URL, parse that URL first.
- Create the parameter collection. Use const params = new URLSearchParams(queryString);.
- Read a single value. Use const page = params.get("page");. It returns the first matching value, or null when the name is absent. Use params.has("page") when you need to distinguish a missing parameter from one whose value is an empty string.
- Read every repeated value. Use const tags = params.getAll("tag");. The returned array preserves the order of matching entries in the query string.
- Convert to an object only when duplicates do not matter. Object conversion can discard repeated names, so retain the URLSearchParams collection or call getAll() for keys that may occur more than once.
For example:
const queryString = "name=Ada&role=admin&tag=js&tag=url";
const params = new URLSearchParams(queryString);
params.get("name") returns "Ada", while params.getAll("tag") returns ["js", "url"] in that order.
Choose the right input form
The most important decision is whether you have query text alone or a complete URL. Both can be handled natively, but they require different constructors.
| Available input | Recommended API | Result |
|---|---|---|
| Query text only | new URLSearchParams(queryText) | A collection of decoded query parameters |
| Complete absolute URL | new URL(absoluteUrl).searchParams | The parameters contained in that URL |
| Current page address | new URL(window.location.href).searchParams | The current document’s query parameters |
For a complete address, use const url = new URL("https://example.com/search?term=url&tag=js"); followed by const params = url.searchParams;. The url.search property contains the serialized query string with its leading question mark, while url.searchParams exposes decoded names and values.
A fragment is not part of the query string. The URL API keeps it in the separate url.hash property. If you are working from raw text, remove a literal #fragment before calling URLSearchParams; an encoded %23 remains ordinary query data.
Read values without losing duplicates
The collection methods have distinct return types. Choosing the right one prevents missing values or accidentally collapsing repeated parameters.
| Method | Behavior |
|---|---|
| get(name) | Returns the first decoded value for name, or null if the name is absent. |
| getAll(name) | Returns every decoded value for name in source order, including an empty array when absent. |
| has(name) | Returns true when the name exists, even if its decoded value is an empty string. |
| entries() | Returns decoded name/value pairs in their original order. |
Object.fromEntries(params.entries()) is concise when every name is unique, but a later duplicate overwrites an earlier value. For a known repeated key, getAll() is simpler. When names are discovered dynamically, you can group them while retaining order:
const grouped = Object.create(null);
for (const [name, value] of params) {
if (!grouped[name]) grouped[name] = [];
grouped[name].push(value);
}
The null-prototype object prevents ordinary property names from colliding with inherited members. In application code, however, a direct getAll() call is usually clearer when the expected parameter names are known.
Handle decoding, empty values, and paths
URLSearchParams applies form-style query decoding, but that behavior should not be generalized to every part of a URL.
- Percent escapes are decoded. A value such as name%20value becomes name value. An escaped ampersand becomes part of one value rather than a separator.
- Plus signs become spaces. In query data, + represents a space. Encode a literal plus as %2B.
- Empty values are valid. A name without an equals sign and a name followed by an empty value both produce an empty decoded value. Check has() when that distinction matters.
- Repeated names remain separate. The collection keeps their original order rather than converting them into one overwritten property.
- Paths follow different rules. A URL pathname and filename remain serialized with percent escapes; they are not decoded by URLSearchParams.
Do not decode an entire query with decodeURIComponent and then split it manually. That approach does not model plus-to-space conversion or parameter boundaries and may throw on malformed escape sequences. Parsing also does not validate a value’s business meaning, so validate decoded input separately and never treat a query parameter as proof of authorization.
Inspect browser-normalized URL results
When debugging an application link, URL Parser provides a local inspection step that uses the browser’s native URL constructor. It shows normalized components and ordered decoded query parameters, helping you compare the browser’s serialized result with what your application expected.
- Paste one absolute HTTP or HTTPS URL without a username or password, and review the input character count.
- Select Parse URL, then inspect the normalized URL, origin, protocol, host, hostname, port, pathname, query string, hash, filename, and ordered decoded query parameters.
- Review potentially sensitive query or hash data, then copy the complete parsed JSON if appropriate. The JSON also includes an ordered array of query-parameter name and value objects.
The tool has a strict boundary. It rejects empty input, relative paths, scheme-relative references, bare domains, and schemes other than HTTP and HTTPS. It also rejects surrounding whitespace, ASCII control characters, raw backslashes, and any URL containing a nonempty username or password. Credentials are rejected before output rather than partially masked.
The input limit is 8,192 UTF-16 code units, the query-parameter limit is 200 entries, and formatted JSON is independently limited to 50,000 code units. Exact boundaries are accepted, the next unit or entry is rejected, and no data is silently truncated.
The normalized URL is the browser’s href serialization rather than necessarily the exact text entered. Scheme and host casing can normalize, a missing root path becomes a slash, internationalized hostnames use ASCII serialization, and a default port is removed. Pathname and filename stay percent-encoded, while query names and values are decoded. The filename comes from the final serialized pathname segment and is empty when the path ends with a slash.
Parsing, display, and copying happen in the current browser tab. The URL is not uploaded to Lizely, and no request is sent to the pasted address. URL Parser never opens or fetches the link, checks whether a site exists, tests redirects, scans its safety, or verifies reachability. Query strings and fragments can contain application secrets, so inspect them before copying or sharing.
Match frontend and backend expectations
The MDN URL documentation describes the browser’s WHATWG-based URL model, while the MDN URLSearchParams documentation defines query-form decoding and collection behavior. URL Parser uses the browser’s WHATWG parser as its authority, but its output is intended for inspection and handoff rather than as a guarantee that another programming language behaves identically.
Server frameworks, legacy parsers, regular expressions, and operating-system APIs can differ around hosts, backslashes, percent encoding, and special schemes. If a frontend and backend must agree, parse the same absolute URL in each environment and compare semantic components and parameter values instead of assuming their raw strings will match.
Most importantly, parsing only reveals what the URL contains. It does not prove ownership, determine whether a destination is malicious, reveal a server-side redirect, check DNS or TLS, or authorize an action.
Avoid fragile manual parsing
Common query-string bugs come from treating URL syntax like a simple delimiter format.
- Splitting manually on an ampersand breaks escaped separators and fails to implement query decoding rules.
- Passing a full URL to URLSearchParams makes the address itself part of the parameter text. Parse the URL first and read searchParams.
- Leaving a fragment in the query mixes two different URL components. Split off a literal hash fragment before parsing raw query data.
- Converting to an object too early can overwrite repeated names. Keep the ordered collection until you know which structure your data requires.
- Applying query decoding to a pathname produces the wrong result because path serialization and query decoding follow different rules.
The shortest reliable pattern for an absolute URL is const url = new URL(absoluteUrl); const params = url.searchParams;. Then use get() for one value and getAll() for repeated names. For query-only input, replace those first two lines with const params = new URLSearchParams(queryText);.
Related reading: How to Use Power Query to Merge Excel Files.