Query String to JSON and Back: +, %20 and Repeated Keys
Last updated: · 5 min read
The part of a URL after the question mark, the query string, carries search filters, page numbers and tracking parameters. It is awkward to read while debugging: a space shows up as + in one place and %20 in another, accented letters turn into byte sequences such as %C3%A9, and the same key may appear several times. The Query String ↔ JSON Converter unpacks the string into a readable JSON object, and when you give it a JSON object starting with { it goes the other way and builds an encoded query string. This guide covers the rules for both directions, the finer points of the application/x-www-form-urlencoded format and the cases the tool deliberately does not support. The outputs in the examples are the tool's real results.
Formula
Rules:
1. The direction is detected automatically: input starting with { is JSON → query string, anything else is query string → JSON.
2. For a URL, everything after # is dropped and the part after the first ? is taken; without a ?, the whole text is treated as a query string.
3. The string is split at & into pieces and each piece at its first = into key and value; a piece without = gets an empty string as its value.
4. In keys and values, + is first turned into a space and the percent-encoding is then decoded as UTF-8.
5. When a key is repeated, its values are collected into an array in order of appearance; every value is a string.
6. In the other direction, each key and value is encoded with encodeURIComponent (a space becomes %20); an array becomes a repeated key, null an empty value, and numbers and booleans their text form.
Input (URL):
https://example.com/search?q=caf%C3%A9+latte&tag=a&tag=b&page=2&debug#top
Output:
{
"q": "café latte",
"tag": [
"a",
"b"
],
"page": "2",
"debug": ""
}
Input (JSON):
{"q":"café latte","tag":["a","b"],"page":2,"ref":null}
Output:
q=caf%C3%A9%20latte&tag=a&tag=b&page=2&ref=There is no formula, only a set of parsing rules for each direction. RFC 3986 defines the query as the part between ? and # and the %HH form of percent-encoding; splitting key=value pairs at & and reading + as a space come from the application/x-www-form-urlencoded rules of the WHATWG URL Standard. encodeURIComponent is defined in ECMA-262 and encodes, as UTF-8 bytes, every character except letters, digits and - _ . ! ~ * ' ( ).
What the inputs mean
- Query string, URL or JSON
- A complete URL, a bare query string (q=a&b=c) or a flat JSON object starting with {. JSON values may be strings, numbers, booleans, null or an array of those; nested objects are not accepted.
Worked example: Unpacking a search URL and rebuilding it
- The first input is a full URL. The #top fragment and the address before ? are discarded, leaving q=caf%C3%A9+latte&tag=a&tag=b&page=2&debug, which is split at & into five pieces.
- In the value of q, + becomes a space and %C3%A9 is decoded as the two-byte UTF-8 form of é: "q": "café latte".
- The key tag occurs twice, so its values are collected into an array: ["a", "b"].
- page is the string "2"; the tool does not turn it into a number. The debug piece has no =, so its value is an empty string: "debug": "".
- The second input is a JSON object and runs in the opposite direction. Output: q=caf%C3%A9%20latte&tag=a&tag=b&page=2&ref= — the space is now encoded as %20, the array is expanded into a repeated tag key and ref, which is null, is written with an empty value.
Result: URL → JSON yields an object with four keys: q, the tag array, page as the string "2" and an empty debug. JSON → query string yields q=caf%C3%A9%20latte&tag=a&tag=b&page=2&ref=.
🔗 Query String ↔ JSON Converter
Free, no sign-up; your data stays in your browser.
Open the calculator →How to read the result
The two directions are not exact inverses, and that is intentional. When reading, both + and %20 are accepted as a space because browser forms and URLSearchParams write spaces as +; when writing, %20 is used because it is safe in every part of a URL. Types do not come back either: the number 2 becomes "2" in the query string and stays a string when parsed again. Data that really contains a plus sign, such as a phone number or Base64, has to arrive encoded as %2B, otherwise the plus is read as a space. Be careful when sharing URLs that carry secret tokens, such as password-reset links. This is general information.
Common mistakes
- Writing a percent sign without encoding it. In q=100%&x=1 the % is not followed by two hex digits, so the tool reports "Malformed percent-encoding: “100%”."; the correct form is 100%25.
- Leaving a literal plus sign in a value. tel=+90555 is read as " 90555"; write %2B for a plus.
- Trying to turn a nested object into a query string. For {"filter":{"a":1}} the tool answers "Nested objects or arrays cannot be converted to a query string: “filter”."; flatten the keys first.
- Expecting bracketed names to expand into arrays or objects. tag[]=a and user[name]=x stay flat keys called "tag[]" and "user[name]"; that notation belongs to certain frameworks, not to the standard.
- Pasting a URL that has no query string. For https://example.com/page the tool reports "The URL has no query string."
- Assuming fields such as page arrive as numbers. Every value is a string; convert with Number() before comparing.
Frequently asked questions
What is the difference between + and %20?
Both can mean a space in a query string, but they come from different rules. %20 is the general percent-encoding of RFC 3986 and is valid in every part of a URL. + belongs to the application/x-www-form-urlencoded format and only means a space in the query string and in form bodies; in the path it is a literal plus sign.
What happens when the same key appears more than once?
The values are collected into an array in order: tag=a&tag=b becomes "tag": ["a", "b"]. A key that occurs once is a plain string rather than an array, so the consuming code has to handle both.
How does encodeURIComponent differ from encodeURI?
encodeURIComponent is meant for a single key or value and also encodes separators such as & = ? and /. encodeURI is designed for a whole address and leaves those separators alone; encode a value with it and an & inside the value starts a new parameter.
Are semicolon-separated parameters supported?
No. Like the WHATWG URL Standard, the tool splits at & only; a=1;b=2 yields a single key a with the value "1;b=2".
Is my URL sent to a server?
No, parsing happens in your browser. It is still good practice to strip session or access tokens from an address before pasting it into any tool.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.