BYTETOOLS

Query String to JSON: Tips, Gotchas and Type Traps

The single biggest gotcha converting a query string to JSON is types: every value comes out as a string, so "2" and "true" are text, not a number or boolean — cast them in your own code. Knowing that, plus how repeated keys and + behave, keeps the output predictable.

The converter is faithful to how URLs actually work, which is exactly why a few results surprise people. Here are the practices and traps worth internalizing.

Best practices

  • Expect strings, cast later. Treat every value as text and convert numbers, booleans, and dates in your application. The JSON reflects the URL, which has no types.
  • Paste the full URL when unsure. You do not need to trim the domain and path — the converter uses only the part after ?, so pasting the whole link avoids accidentally cutting a parameter.
  • Check array-shaped fields. If a field you expected to be single is an array, a key repeated in the input. Decide whether your code should read the first value or all of them.
  • Convert privately. Because it runs locally, use it freely on URLs containing session tokens or IDs — nothing is logged or uploaded.

Gotchas and how they behave

InputOutputWhy
n=2"n": "2"All values are strings
ok=true"ok": "true"No boolean type in URLs
a=1&a=2"a": ["1","2"]Repeated key becomes array
q=a+b"q": "a b"+ decodes to a space
x="x": ""Empty value is kept

Common mistakes

A frequent error is assuming a numeric-looking value is a number and doing math on it directly — you will concatenate strings instead. Another is needing a literal plus sign: in a query string a real + must be encoded as %2B, otherwise it decodes to a space. People also forget that keys are case-sensitive, so Page and page produce two different JSON fields. Finally, if a value contains what looks like nested structure, such as filter=a:1,b:2, the converter keeps it as one string — it does not parse sub-syntax you invented.

Troubleshooting the output

If a value looks wrong, decode it in isolation with a URL decoder to confirm what the original characters were. If a field is unexpectedly an array, search the input for a repeated key. And if the JSON is empty, check that your input actually contained a ? or valid pairs — a bare word with no = has nothing to split. When in doubt, convert a known-good example first to confirm the tool behaves as you expect, then run your real input and compare — the difference usually points straight at the offending parameter.

Try the Query String to JSON converter — free and 100% in your browser.

FAQ

Why is my number a string in the JSON?

Query strings only carry text, so there is no way to know 2 is a number. The converter preserves it as "2"; cast it to a number in your code.

How do I keep a literal plus sign?

Encode it as %2B in the URL. An unencoded + is defined to mean a space and will decode to one.

Why did two parameters merge into an array?

They shared the same key. The converter groups repeated keys into an array so no value is lost — this is expected behavior, not a bug.

Does it parse nested or dotted keys into objects?

No. A key like user.name stays a single flat field named user.name; the tool does not expand dot or bracket notation into nested objects.

Related free tools

Built by ByteVancer

ByteTools is a free product of ByteVancer, a software and web development studio building web apps, SaaS, and custom software. When your data plumbing outgrows a converter, explore how ByteVancer can build the real pipeline.