String to JSON Converter

Convert JS object literals, URL query strings, or key-value lines into strict, formatted JSON. Free, browser-based, and built for everyday development tasks.

Browser-basedFree foreverNo signup required3 min read

Quick Answer

The String to JSON Converter turns JS object literals, URL query strings, and key-value lines into strict formatted JSON — auto-detecting the input format. No eval(), everything runs in your browser.

About String to JSON Converter

Half the "invalid JSON" errors in day-to-day work come from text that is almost JSON but not quite: a JavaScript object copied from source code (single quotes, unquoted keys, trailing commas), a query string from a URL, or a block of key: value lines from a config or log. This converter recognizes those formats and produces strict JSON from them — using safe text transforms and parsers rather than eval(), so nothing in the pasted text ever executes.

Why use this tool?

  • JS object → JSON — convert objects copied from JavaScript/TypeScript source into valid JSON for configs and APIs
  • Query string → JSON — turn URL parameters into a structured object for documentation or test fixtures
  • Config extraction — convert key=value or key: value lines (env files, INI-ish configs, log context) into JSON
  • Fixing near-JSON — repair trailing commas, single quotes, and unquoted keys in one click
  • API test data — build strict JSON payloads quickly from whatever loose format you have on hand

How it works

  1. 1Paste the string — a JS object literal, a URL or query string, or key-value lines
  2. 2Leave the mode on Auto-detect, or choose the format explicitly if detection guesses wrong
  3. 3Click Convert — the tool applies the matching safe transform and validates the result with JSON.parse
  4. 4The output panel names the detected format and shows the pretty-printed JSON

Common mistakes to avoid

  • Expecting code execution — values that are variables, function calls, or template literals cannot be converted; only static literal syntax can become JSON
  • Ambiguous auto-detection — a single line like "a=1" could be a query string or a key-value line; when the guess is wrong, pick the mode explicitly
  • Nested quotes in JS strings — a single-quoted string containing an unescaped apostrophe (like 'it's') is invalid JS too; fix the source string first
  • Numbers vs strings from query strings — query-string values are always strings ("1", not 1) because URLs carry no type information; cast types downstream where it matters

Pro tip

For one-off conversions inside an editor, pasting a JS object into a Node REPL and calling JSON.stringify(obj, null, 2) also works — but this tool is safer for text from untrusted sources, since it never evaluates the input as code.

Frequently Asked Questions

What is the String to JSON Converter?
The String to JSON Converter turns almost-JSON text into strict, valid JSON. It handles JavaScript object literals (single quotes, unquoted keys, trailing commas), URL query strings, and key-value line formats — outputting formatted JSON you can use anywhere.
How do I use the String to JSON Converter?
Paste your string, leave the mode on Auto-detect (or pick JS object / query string / key-value explicitly), and click Convert. The tool reports which format it detected along with the JSON output.
Is my data private?
Yes. All conversion logic runs in your browser — no eval(), no server round-trip, nothing stored.
What JS object syntax can it fix?
It quotes unquoted keys ({name: → {"name":), converts single-quoted strings to double-quoted, and removes trailing commas — the three differences that make copy-pasted JavaScript objects invalid JSON. Genuinely dynamic syntax (functions, variables, template literals) cannot be converted.
How are query strings converted?
Each parameter becomes a key with its decoded value ("a=1&b=hello%20world" → {"a": "1", "b": "hello world"}). Repeated keys become arrays. A full URL works too — everything before the ? is ignored.

Related Workflows

Related Tools

Compare

Tool Trust & Transparency

Ecosystem Trust Center

Processed in

Your browser

Input never sent to any server

Input stored

No

No logs, no accounts required

Common use cases

  • Format, validate, or transform code and data without leaving your browser
  • Debug encoding, decoding, or conversion issues quickly
  • Generate test data or convert between formats in development workflows

Limitations

  • Operates entirely in your browser — large inputs may slow older devices
  • Output is a best-effort conversion; always validate critical results independently

Last verified: 2026 · Free, no account required · Validate critical output independently

Report an issue →