Skip to main content
Back to Blog

JSON to Query String: simplifying API Requests in 2025

Turn JSON objects into GET query strings with correct encoding and array handling so your API URLs always work.

Kashyap Thakar
8 min
JSONAPIURLDevelopment
JSON to Query String: simplifying API Requests in 2025

Modern web applications communicate constantly via APIs. While JSON is the standard for request bodies (POST/PUT), GET requests typically rely on query strings. Manually converting complex JSON objects into URL-encoded query parameters is tedious, error-prone, and one of the most common sources of frustration for frontend developers.

The Challenge with GET Requests

Unlike POST requests where you can simply send a JSON blob in the body, GET requests require parameters to be appended to the URL. This limits the data types we can send to essentially just strings.

// JSON input
{ "search": "query", "page": 1, "filters": { "date": "today", "status": ["active", "pending"] } }

Converting the above manually into a string involves several decisions that affect compatibility with your backend framework.

Handling Arrays: The Great Divide

There is no single standard for how arrays should be represented in a query string. Different server-side frameworks expect different formats:

1. Repeating Keys (Java/Spring, .NET)

The key is repeated for each value.

?status=active&status=pending

2. Bracket Notation (PHP, Rails, Node.js libraries)

Brackets explicitly denote an array.

?status[]=active&status[]=pending

3. Comma Separated (Custom/Simple)

Single key with values separated by a delimiter.

?status=active,pending

The Complexity of Nesting

Things get even messier with nested objects. Should `filters.date` become `filters[date]` or `filters.date`?

  • Bracket Notation: `filters[date]=today` (Standard in `qs` library)
  • Dot Notation: `filters.date=today` (Common in elasticsearch or filtering APIs)
  • JSON Stringified: filters={"date":"today"} (Sometimes used but requires double encoding)

URL Encoding Essentials

A common novice mistake is concatenating strings without encoding. Special characters have reserved meanings in URLs:

  • `&` starts a new parameter
  • `=` separates key and value
  • `#` starts a fragment
  • ` ` (space) breaks the URL

If your search query is "Time & Tide", sending `?q=Time & Tide` will be interpreted as two parameters: `q="Time "` and a loose param `Tide`. Correct encoding `Time%20%26%20Tide` is mandatory.

Why Use a Converter?

Writing your own serializer is possible (`Object.keys(params).map(...)`), but it often misses edge cases like `null` values, complex nesting, or proper encoding.

Using a dedicated tool ensures reliability. It handles:

  • Recursively flattening nested objects
  • Standardizing array serialization
  • Encoding keys and values automatically
  • Removing undefined or null keys to keep the URL clean

Common Serialization Libraries

JavaScript/TypeScript

  • URLSearchParams: Native browser API, but limited support for nested objects and arrays
  • qs: Popular npm package with extensive options for array and object serialization
  • query-string: Lightweight alternative with good TypeScript support

Python

  • urllib.parse.urlencode: Standard library, handles basic cases
  • requests: Popular HTTP library with built-in parameter handling

Real-World Examples

E-commerce Search Filters

Converting complex filter objects into query strings:


{
  "category": "electronics",
  "price": { "min": 100, "max": 500 },
  "brands": ["Samsung", "Apple"],
  "inStock": true
}
                    

Becomes: ?category=electronics&price[min]=100&price[max]=500&brands[]=Samsung&brands[]=Apple&inStock=true

API Pagination

Pagination parameters are commonly converted to query strings:


{
  "page": 2,
  "limit": 20,
  "sort": { "field": "created_at", "order": "desc" }
}
                    

Edge Cases to Handle

  • Null and undefined values: Should they be included or omitted?
  • Empty arrays: Represent as empty brackets or omit entirely?
  • Nested arrays: How to represent arrays within arrays?
  • Special characters: Ensure proper URL encoding
  • Boolean values: Convert to strings ("true"/"false") or numeric (1/0)?

Try It Yourself

Stop writing boilerplate code to serialize params or debugging malformed URLs. Use our JSON to Query String Converter to automate this process. It handles:

  • Encoding, nesting, and array serialization automatically
  • Multiple array format options (repeating keys, brackets, comma-separated)
  • Nested object flattening with bracket or dot notation
  • Proper handling of null, undefined, and empty values
  • URL-safe encoding of special characters

This lets you focus on the actual API logic instead of wrestling with URL construction. Perfect for debugging API calls, testing different parameter formats, and learning how query strings work.

Part of the ThenCatch blog. Learn more about us or browse more guides.