Eskillsfy

Home / Blog / Data and formats

Data and formats · 23 Nov 2026

Query String to JSON: how it works and how to build one

Turn URL parameters into JSON and JSON into a query string. This guide explains what happens behind the button and shows the code, so you can build your own.

What it does

Paste a full URL or just the part after the ?, and every parameter becomes a JSON key. Repeated keys become arrays. Going the other way builds a properly encoded query string from a JSON object.

When to use it

  • Debugging tracking links (utm_ parameters)
  • Building API requests
  • Reading search URLs

How to use it

  1. Choose Query → JSON or JSON → Query.
  2. Paste a URL, query string or JSON object.
  3. Copy the result.

Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/query-string-to-json

How it works

Browsers ship URLSearchParams, which already knows how to split a query string and decode %20 and + into spaces. The tool loops over its entries and builds an object, turning repeated keys into arrays.

The reverse builds a URLSearchParams from an object and calls toString(), which encodes everything correctly.

Build it yourself

Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.

queryJson.ts (ts)

export function queryToJson(input: string) {
  const query = input.includes("?") ? input.split("?")[1].split("#")[0] : input;
  const out: Record<string, string | string[]> = {};
  for (const [k, v] of new URLSearchParams(query)) {
    const prev = out[k];
    out[k] = prev === undefined ? v : Array.isArray(prev) ? [...prev, v] : [prev, v];
  }
  return out;
}

export function jsonToQuery(obj: Record<string, unknown>) {
  const p = new URLSearchParams();
  for (const [k, v] of Object.entries(obj)) {
    for (const item of Array.isArray(v) ? v : [v]) if (item != null) p.append(k, String(item));
  }
  return p.toString();
}

Make it production-ready

  • Support key[] style arrays used by PHP and Rails.
  • Show the URL’s other parts (host, path, hash) in a table.

Questions

How are repeated keys handled?

size=M&size=L becomes “size”: [“M”, “L”].

Try the Query String to JSON

Free, runs in your browser, nothing is uploaded.

Open it
Keep reading

More in Data and formats

All posts