Skip to main content
CalcChef

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.

Options

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 optionQuery string
Repeated key (default)tags=red&tags=blue&user%5Bname%5D=Ann%20Lee
Bracketstags%5B%5D=red&tags%5B%5D=blue&user%5Bname%5D=Ann%20Lee
Indexestags%5B0%5D=red&tags%5B1%5D=blue&user%5Bname%5D=Ann%20Lee
Comma listtags=red%2Cblue&user%5Bname%5D=Ann%20Lee
One JSON valuetags=%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 optionQuery string
Brackets (default)tags=red&tags=blue&user%5Bname%5D=Ann%20Lee
Dotstags=red&tags=blue&user.name=Ann%20Lee
One JSON valuetags=red&tags=blue&user=%7B%22name%22%3A%22Ann%20Lee%22%7D

Same input as above.

Spaces, brackets, ? and nulls

OptionJSONQuery 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 tools