About the JSON to String
Turn JSON into a string literal that you can paste straight into code, with escaping for JavaScript, Java, C# or Python.
Key features
- String literals for JavaScript, Java, C#, Python and PHP
- Correct escaping rules for each language
- Optional minification to keep literals short
- C# verbatim strings and PHP single-quoted strings
- Ready to paste into source code or tests
- Instant, private
Paste JSON into code without escaping errors
Test fixtures, mock API responses, sample payloads in documentation, and hard-coded configuration all require JSON inside a string literal. Every language escapes quotes differently, and getting it wrong causes syntax errors. Pick your language and this tool produces a ready-to-paste literal.
Output for each language
Input: {"name":"Ada","admin":true}
| Language | Output |
|---|---|
| JavaScript | const json = "{\"name\":\"Ada\",\"admin\":true}"; |
| Java | String json = "{\"name\":\"Ada\",\"admin\":true}"; |
| C# | var json = @"{""name"":""Ada"",""admin"":true}"; |
| Python | data = "{\"name\":\"Ada\",\"admin\":true}" |
| PHP | $json = '{"name":"Ada","admin":true}'; |
Language notes
- JavaScript / TypeScript: you could also use a template literal (backticks) or simply write the object directly; a string is useful when you specifically need to test
JSON.parse. - Java 15+: text blocks (
""") let you paste formatted JSON without escaping; this tool targets classic string literals that work in every version. - C# 11+: raw string literals (
""") avoid escaping entirely. - Python: a single-quoted string often needs no escaping at all for JSON; the double-quoted form shown works everywhere.
- PHP: single quotes don't interpolate variables, which makes them the safest choice for JSON.
Typical uses
- Unit tests that parse or post JSON.
- Mocking HTTP clients (WireMock, nock, MSW, Moq).
- Constants for default configuration.
- Code samples in documentation.
Related tools
For a JSON string literal to embed inside other JSON, use JSON Stringify. For PHP arrays rather than strings, use JSON to PHP Array. For Java classes, see JSON to Java.
How to use the JSON to String
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The String appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.