JSON ⇄ GET Converter

Convert JSON objects to GET query strings and parse query strings back to JSON with support for nested objects and arrays.

Back to all tools on ToolForge

More in JSON & API

JSON Object



GET Query String

About JSON ⇄ GET Converter

This converter transforms JSON objects into GET query strings (e.g., ?key=value&arr=a&arr=b) and parses query strings back into JSON. It handles nested objects using bracket notation and arrays as repeated keys.

It is useful for building API URLs with dynamic parameters, testing query-based endpoints, converting filter objects to URLs, or extracting JSON data from existing query strings for debugging.

Conversion Examples

Simple object:
{"name": "John", "age": 30}
→ name=John&age=30

Array values (repeated keys):
{"tags": ["a", "b", "c"]}
→ tags=a&tags=b&tags=c

Nested objects (bracket notation):
{"user": {"name": "John", "age": 30}}
→ user[name]=John&user[age]=30

Complex nested with array:
{"filter": {"status": "active", "tags": ["web", "api"]}}
→ filter[status]=active&filter[tags]=web&filter[tags]=api

Full URL example:
https://api.example.com/users?name=John&age=30&tags=a&tags=b

Query String Encoding Rules

CharacterEncodedNotes
(space)%20 or +Both accepted; + common in forms
&%26Separator between pairs
=%3DSeparates key from value
?%3FStarts query string
#%23Starts fragment (not sent)
/%2FPath separator
Non-ASCII%XX bytesUTF-8 percent encoded

JavaScript Implementation

// JSON to query string (handles nested/arrays)
function jsonToQuery(obj, prefix) {
  const pairs = [];
  for (const key in obj) {
    if (!obj.hasOwnProperty(key)) continue;
    const fullKey = prefix ? prefix + "[" + key + "]" : key;
    const value = obj[key];

    if (value === null || value === undefined) continue;

    if (Array.isArray(value)) {
      value.forEach(v => {
        pairs.push(encodeURIComponent(fullKey) + "=" + encodeURIComponent(v));
      });
    } else if (typeof value === "object") {
      pairs.push(...jsonToQuery(value, fullKey));
    } else {
      pairs.push(encodeURIComponent(fullKey) + "=" + encodeURIComponent(value));
    }
  }
  return pairs.join("&");
}

// Query string to JSON
function queryToJson(queryString) {
  const params = new URLSearchParams(queryString.replace(/^\?/, ""));
  const result = {};

  for (const [key, value] of params) {
    if (result.hasOwnProperty(key)) {
      if (!Array.isArray(result[key])) {
        result[key] = [result[key]];
      }
      result[key].push(value);
    } else {
      result[key] = value;
    }
  }

  // Single-element arrays become scalars
  for (const key in result) {
    if (Array.isArray(result[key]) && result[key].length === 1) {
      result[key] = result[key][0];
    }
  }

  return result;
}

Common Use Cases

Use CaseExample JSONQuery String
Search filters{"q": "api", "page": 2}q=api&page=2
Multi-select{"tags": ["js", "css"]}tags=js&tags=css
Range filter{"min": 0, "max": 100}min=0&max=100
Sort options{"sort": "date", "order": "desc"}sort=date&order=desc
Nested filters{"user": {"role": "admin"}}user[role]=admin

Frequently Asked Questions

What is a query string?
A query string is the part of a URL after the question mark (?) containing key-value pairs separated by ampersands (&). Format: ?key1=value1&key2=value2. Query strings send data via GET requests, used for filters, pagination, search parameters, and API queries.
How are arrays represented in query strings?
Arrays can be represented multiple ways: repeated keys (tags=a&tags=b), bracket notation (tags[]=a&tags[]=b), or indexed (tags[0]=a&tags[1]=b). This tool uses repeated keys by default. Server-side parsing determines how duplicates are handled (array vs last value wins).
How are nested objects flattened?
Nested objects use bracket notation: {user: {name: 'John'}} becomes user[name]=John. Arrays in objects: {filter: {tags: ['a','b']}} becomes filter[tags]=a&filter[tags]=b. This flat key-value structure preserves the hierarchy while remaining URL-compatible.
What characters are encoded in URLs?
Special characters are percent-encoded: space→%20 (or +), &→%26, =→%3D, ?→%3F, #→%23, non-ASCII→UTF-8 bytes. JavaScript's encodeURIComponent() handles this automatically. Always encode values, and optionally encode keys if they contain special characters.
What is the query string length limit?
No official HTTP spec limit, but practical limits exist: IE ~2048 chars, older browsers ~2000 chars, servers vary (Apache ~8KB, IIS ~16KB). For large data, use POST with JSON body. Keep query strings under 2000 characters for maximum compatibility.
How do I parse query strings in JavaScript?
Use URLSearchParams: const params = new URLSearchParams(window.location.search); params.get('key'); params.getAll('key'); for modern browsers. For Node.js: require('querystring').parse(). This tool handles nested objects and arrays that URLSearchParams doesn't natively support.