JSON to Query String
Turn a JSON object into a URL query string: arrays as repeated keys, [], [0], a comma list or JSON, nested objects as user[name], user.name or JSON. How it works
Use the JSON to Query String
One JSON object, up to 1,000,000 characters; longer text is not truncated, it is refused with a message. The text is read by JSON.parse, so a key written twice keeps its last value, a key that is a whole number ("2") moves ahead of the others, and a number beyond 2^53 loses digits.
6 parameters.
About the JSON to Query String
The default object {"name": "John Doe", "age": 30, "tags": ["red", "blue"], "address": {"city": "New York", "zip": "10001"}} becomes name=John%20Doe&age=30&tags=red&tags=blue&address%5Bcity%5D=New%20York&address%5Bzip%5D=10001. Each key becomes a parameter, spaces are %20 and a nested object is written address[city] with the brackets escaped; options change how arrays, nested objects, nulls and spaces are written and whether the string starts with ?.
Array styles
| Arrays option | Query string |
|---|---|
| Repeated key (default) | tags=red&tags=blue&user%5Bname%5D=Ann%20Lee |
| Brackets | tags%5B%5D=red&tags%5B%5D=blue&user%5Bname%5D=Ann%20Lee |
| Indexes | tags%5B0%5D=red&tags%5B1%5D=blue&user%5Bname%5D=Ann%20Lee |
| Comma list | tags=red%2Cblue&user%5Bname%5D=Ann%20Lee |
| One JSON value | tags=%5B%22red%22%2C%22blue%22%5D&user%5Bname%5D=Ann%20Lee |
Input: {"tags": ["red", "blue"], "user": {"name": "Ann Lee"}} with the other options at their defaults.
Nested object styles
| Nested objects option | Query string |
|---|---|
| Brackets (default) | tags=red&tags=blue&user%5Bname%5D=Ann%20Lee |
| Dots | tags=red&tags=blue&user.name=Ann%20Lee |
| One JSON value | tags=red&tags=blue&user=%7B%22name%22%3A%22Ann%20Lee%22%7D |
Same input as above.
Spaces, brackets, ? and nulls
| Option | JSON | Query string |
|---|---|---|
| Space is written as + | {"tags": ["red", "blue"], "user": {"name": "Ann Lee"}} | tags=red&tags=blue&user%5Bname%5D=Ann+Lee |
| Leave [ ] unescaped | {"tags": ["red", "blue"], "user": {"name": "Ann Lee"}} | tags=red&tags=blue&user[name]=Ann%20Lee |
| Start with ? | {"tags": ["red", "blue"], "user": {"name": "Ann Lee"}} | ?tags=red&tags=blue&user%5Bname%5D=Ann%20Lee |
| Null as the text null (default) | {"a": null, "b": 1} | a=null&b=1 |
| Null as an empty value | {"a": null, "b": 1} | a=&b=1 |
| Leave the parameter out | {"a": null, "b": 1} | b=1 |
Frequently asked questions
- How do I convert JSON to a query string?
- Paste one JSON object into the box. The query string updates as you type, with the number of parameters under it (6 for the default example), and the copy button takes it. An array, a string or a number on its own is refused: the input must be an object such as {"a": 1}.
- How are arrays written in a query string?
- There is more than one convention, so pick the one your server reads. For tags ["red", "blue"] the tool writes tags=red&tags=blue (Repeated key), tags[]=red&tags[]=blue (Brackets), tags[0]=red&tags[1]=blue (Indexes), tags=red,blue (Comma list) or tags=["red","blue"] (One JSON value), with the brackets, comma and quotes percent-encoded.
- How are &, = and other special characters encoded?
- Everything except A-Z, a-z, 0-9 and - . _ ~ is percent-encoded as UTF-8, so {"q": "a&b=c?d#e", "x": "café 50%"} gives q=a%26b%3Dc%3Fd%23e&x=caf%C3%A9%2050%25. An & or = inside a value can then not be mistaken for the start of the next parameter.
- Should spaces be %20 or +?
- The tool writes %20 by default, which reads as a space anywhere in a URL. Choose + for form encoding, where + stands for a space in the query string only, never in a path: "Ann Lee" becomes Ann+Lee.
- What happens to an array of objects?
- With Repeated key, {"items": [{"id": 1}, {"id": 2}]} gives items%5Bid%5D=1&items%5Bid%5D=2 and a note that the objects run together, because the same name repeats for each object. Indexes keep them apart: items%5B0%5D%5Bid%5D=1&items%5B1%5D%5Bid%5D=2.
- Why did a key move or disappear?
- The text is read by JSON.parse: a key written twice keeps its last value, and a key that is a whole number comes before the others. {"b": 1, "2": "x", "b": 3} gives 2=x&b=3. An empty array or object writes no parameter in the repeat, bracket, index and dot styles, and a note says so.
Related Tools
View all toolsSubnet Mask Calculator
Subnet calculator for IPv4: enter an address and a mask or prefix such as /24 to get the network, broadcast address, host range, usable hosts and wildcard mask.
CIDR Calculator
Enter an IPv4 CIDR block such as 192.168.1.0/24 for its IP range, netmask, broadcast address and usable hosts, split it into subnets or turn a range into CIDR.
JWT Decoder
Paste a JSON Web Token to read its header, its payload and the exp, nbf and iat times in UTC. The signature is shown but not checked: nothing is verified.
URL Parser
Split a URL into protocol, user name, password, host, port, path, query and hash, see each query parameter decoded, and whether the port was written.
Query String to JSON
Paste a query string or a full URL to get JSON: repeated keys and key[] become arrays, + and %20 decode to spaces, with optional nesting and number types.
UTM Builder
Build a campaign URL with utm_source, utm_medium, utm_campaign, utm_id, utm_term and utm_content. Source, medium and campaign are required.