Skip to content
gohacks.dev
APIs

Query String to JSON

Parse a URL's query string into JSON, with PHP-style brackets for nested keys and lists, or build a query string from a JSON object.

Free · No sign-up · Your inputs stay in your browser

Input

Parse a query string into JSON

Output

Result

164 characters

Brackets follow PHP's convention: filter[status]=x becomes a nested key and tags[]=a&tags[]=b a list, which is what $request->query() and http_build_query() use. Node's URLSearchParams does not nest; the qs package does.

Runs in this browser. Nothing you paste is sent to a server.

Brackets are a convention

Nothing in RFC 3986 says what a query string means; it is opaque text after the ?. PHP decided that brackets build arrays, Rails and the qs package for Node followed, and Laravel's $request->query('filter.status') reads the nested result. URLSearchParams in the browser keeps keys flat, brackets and all.

Repeated keys

Without brackets, a repeated key such as ?tag=a&tag=b keeps only the last value in PHP, while URLSearchParams.getAll('tag') returns both. APIs consumed from several languages are safest with one value per key, or explicit brackets.

Share

Frequently asked questions

How do I send an array in a query string?
With PHP, Laravel or Rails on the server, repeat the key with brackets: ids[]=1&ids[]=2. Other servers may expect ids=1,2 or repeated ids=1&ids=2.
Is + a space in a query string?
In application/x-www-form-urlencoded data, which query strings usually are, yes. URLSearchParams and PHP both decode + as a space.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools