JSON Escaped String ↔ Plain Text Converter

Convert JSON-escaped strings to readable plain text and vice versa, with validation for proper JSON string format.

JSON Escaped String to Plain Text

What is JSON String Escaping?

In JSON, strings containing special characters like newlines (\n), tabs (\t), double quotes (\"), and backslashes (\\) must be escaped to be valid. This tool converts between these escaped JSON string literals and their plain text equivalents.

JSON string escaping ensures that text data can be safely included in JSON structures for APIs, configuration files, and data storage.

How JSON String Escaping Works

  1. For JSON Escaped String to Plain Text: Use JSON.parse() to parse and unescape the string literal into the original plain text.
  2. The result is a primitive string, displayed directly without further formatting.
  3. For Plain Text to JSON Escaped String: Use JSON.stringify() to escape the plain text into a valid JSON string literal.
  4. Errors are caught and displayed if the input for unescaping is not a valid JSON string.

Common Uses of JSON String Escaping

  • Data Interchange: Unescaping JSON string values from API responses to display readable text.
  • Configuration Files: Escaping plain text values with special characters for valid JSON configs.
  • API Responses: Preparing plain text data by escaping it before sending as JSON strings.
  • Logging and Debugging: Unescaping escaped strings in logs to view original content.

JSON String Escaping in Different Programming Languages

Here's how you can unescape JSON strings and escape plain text in various popular languages:

JavaScript

Unescape (JSON Escaped String to Plain Text):

const text = JSON.parse('"hello\\nworld"');

Escape (Plain Text to JSON Escaped String):

const jsonString = JSON.stringify('hello\nworld');

Python

Unescape:

import json
text = json.loads('"hello\\nworld"')

Escape:

import json
json_string = json.dumps('hello\nworld')

Java

Unescape:

import com.google.gson.Gson;
Gson gson = new Gson();
String text = gson.fromJson('"hello\\nworld"', String.class);

Escape:

import com.google.gson.Gson;
Gson gson = new Gson();
String jsonString = gson.toJson("hello\nworld");

PHP

Unescape:

$text = json_decode('"hello\\nworld"');

Escape:

$jsonString = json_encode('hello\nworld');

C#

Unescape:

using Newtonsoft.Json;
string text = JsonConvert.DeserializeObject<string>(""hello\\nworld"");

Escape:

using Newtonsoft.Json;
string jsonString = JsonConvert.SerializeObject("hello\nworld");

More Developer Tools

Timestamp Converter
Convert timestamps to human-readable dates and vice versa, with timezone support.
Base64 Converter
Encode and decode Base64 strings from text or files.
Test Data Generator
Free and easy-to-use online test data generator. Create realistic fake data for testing and development using various data types.