JSON → string
JSON to String: Turn a JSON Object into a String
Convert a JSON object to a string for logs, database columns, URL parameters and code, and turn the string back into JSON. Free, in your browser.
Runs entirely in your browser — nothing you paste is uploaded
Everything runs in your browser. Nothing is sent anywhere.
How it works
JSON to string, in plain terms
A JSON object lives in memory; a string is what you send somewhere. Converting JSON to a string means serialising the value into text — either plain JSON text, or a quoted, escaped literal that can sit inside another piece of text such as a log line, a database column or a URL parameter.
This page does both directions. JSON → string takes your JSON and returns it as text you can copy. string → JSON takes that text back into a readable, indented JSON document. Both run in your browser, no upload.
Three things people mean by "JSON to string"
It is worth naming them, because picking the wrong one is the most common reason a payload arrives broken:
- Serialise to JSON text.
{"id":1}stays{"id":1}— still JSON, just as a string variable in your program instead of an object. This is whatJSON.stringify()gives you. - Serialise to an escaped string literal. The JSON gets wrapped in quotes and every inner quote gets a backslash:
"{\"id\":1}". That is the form you paste into source code, a.envfile or a nested JSON field. Use the JSON escape page when you need exactly this. - Stringify for humans. Same JSON, but with line breaks and indentation you can read. That is a formatting choice, not a different conversion.
Converting in each language
- JavaScript / TypeScript —
JSON.stringify(value)for text,JSON.stringify(value, null, 2)for readable text,JSON.stringify(JSON.stringify(value))when you need the escaped literal. Never useString(value)orvalue + ''— you get[object Object]. - Python —
json.dumps(obj)gives a string;indent=2prettifies it andensure_ascii=Falsekeeps accented characters and CJK readable. - Java — Jackson:
objectMapper.writeValueAsString(value). Gson:new Gson().toJson(value). - C# —
JsonSerializer.Serialize(value), optionally withWriteIndented = true. - PHP —
json_encode($value), withJSON_PRETTY_PRINTfor readable output. Remember thatjson_encodereturnsfalseon failure instead of throwing. - Go —
json.Marshal(value)— the result is a[]byte, convert withstring(b). - SQL — most engines can emit JSON text from a query (
to_json,JSON_OBJECT,FOR JSON PATH); wrap it with the quoting function of your engine before storing it in a text column.
Where the string goes
Logs. A single-line JSON string makes each entry greppable; pretty-printed JSON breaks every line into its own log record, which is why most loggers want the compact form.
Database columns. A TEXT or JSON column takes the string form. Watch the column length — MySQL's old TEXT caps at 65 KB and silently truncates in some drivers.
URL parameters. A query string is not a place for raw JSON. Escape the string, then percent-encode it; or Base64 it; or POST it as a body. Sending raw JSON in a query string works in a few clients and breaks in the rest.
Embedding in code or config. This is the escaped-literal case. Keep the outer quotes, and do not hand-edit the backslashes.
Passing between services. If the receiver expects a string field but you send an object, you get a validation error. Double-check which layer is responsible for the serialisation.
Turning the string back into JSON
The reverse direction is JSON.parse() in JavaScript, json.loads() in Python, JsonSerializer.Deserialize in C#, json_decode() in PHP. Two rules save most debugging sessions:
- Parse once per serialisation. A payload that was stringified twice needs parsing twice. The error after the first parse (
Unexpected token {) is the giveaway. - Do not parse something that is already an object.
JSON.parse(obj)throws because the argument is not a string; check the type first.
If the string came back from a CSV, an Excel cell or a log viewer, it is probably quote-mangled: doubled quotes ("") and stray wrappers are the usual damage. Paste it into the string → JSON tab and the position of the error is reported in the input pane.
Mistakes worth avoiding
- Pretty-printing before sending. Indentation is whitespace, and whitespace costs bytes and breaks single-line protocols. Format for humans, send compressed.
- Assuming key order. JSON objects are unordered. If order matters, use an array.
- Losing precision. JavaScript numbers are doubles; large 64-bit IDs lose their tail when they round-trip through
JSON.parse. Keep IDs as strings. - Trailing commas. Valid in JavaScript objects, invalid in JSON. The same goes for comments.
- Encoding mismatches. Non-ASCII characters are fine in UTF-8 JSON, but a client that re-encodes to Latin-1 will turn them into mojibake. Escaping to
\uXXXXavoids that at the cost of readability.
Using the tabs above
JSON → string: paste the object or array. Pick 2 spaces, 4 spaces or minified output, press Convert. The result appears in a copyable, downloadable pane.
String → JSON: paste the text form and press Convert. If it fails, the message gives the line and column, and the text around it, so you can fix the source instead of guessing.
Need an escaped literal for source code, or a JavaScript object literal with unquoted keys? Use JSON escape or the main JSON stringify converter.
Privacy
Nothing you paste leaves the browser. There is no server-side step, no logging and no storage, so production payloads are fine to paste here.
FAQ
How do I convert a JSON object to a string in JavaScript?
Use JSON.stringify(value) for JSON text, or JSON.stringify(value, null, 2) if you want it readable. If you need a quoted, escaped literal for source code, stringify twice. String(value) does not work — it returns [object Object].
Do I need to parse twice to get JSON back from a string?
Yes, if you serialised twice. Each JSON.stringify adds one layer, so each JSON.parse removes one. If the first parse throws, the text was only serialised once; if it returns another string, parse again.
Does the order of keys or the indentation survive the round trip?
Object keys are unordered and indentation is only whitespace. If a system depends on key order, move it to an array. Pretty-printing is for humans — send the minified form.
Is the string form safe to store or log?
No. JSON is text, and parsing it back gives you plain data. Escaping is not encryption either — it is one call away from readable text. Use real encryption if the payload is sensitive.
Why does the string → JSON direction reject my text?
The most common causes are single-quoted keys, trailing commas, comments, a literal line break inside a string, or a 64-bit number that exceeded JavaScript's integer precision. The error message points at the line and column.