A string is a piece of text in JSON. It can contain letters, numbers, symbols, or even be empty.
Every string must be written inside double quotation marks (").
Here are some valid string examples:
[
"Hello",
"Welcome to JSON",
"12345",
"",
"😊"
]
Notice that all the values are inside double quotes.
"Hello" is a string."12345" is also a string because it is inside quotes."" is an empty string, which means it contains no characters.JSON only allows double quotes for strings.
✅ Correct
{
"city": "London"
}
❌ Wrong
{
"city": 'London'
}
Why is it wrong? JSON does not allow single quotes (') for strings.
Sometimes you need to include special characters inside a string. JSON uses a backslash (\) before these special characters. These are called escape characters.
Use \" when you want to include double quotes inside a string.
{
"message": "She said, \"Good morning!\""
}
Use \\ to display a backslash.
{
"path": "C:\\Users\\Alex"
}
A forward slash usually does not need to be escaped, but JSON allows it.
{
"website": "https:\/\/example.com"
}
Use \n to move text to the next line.
{
"text": "Line 1\nLine 2"
}
Use \t to insert a tab space.
{
"text": "Name\tAge"
}
\b represents a backspace character. It removes the character before it when processed by some programs.
{
"example": "ABC\bD"
}
\f represents a form feed, which is mainly used when printing documents or moving to a new page.
{
"example": "Page1\fPage2"
}
\r moves the cursor back to the beginning of the current line.
{
"text": "Hello\rWorld"
}
Use \u followed by four hexadecimal digits to represent a Unicode character.
{
"letter": "\u0042"
}
Here, 0042 is the Unicode value for the letter B.
| Escape Character | Meaning | Example |
|---|---|---|
\" | Double quote | "He said, \"Hi!\"" |
\\ | Backslash | "C:\\Files" |
\/ | Forward slash | "https:\/\/example.com" |
\n | New line | "Hello\nWorld" |
\t | Tab | "Name\tAge" |
\b | Backspace | "ABC\bD" |
\f | Form feed | "Page1\fPage2" |
\r | Carriage return | "Hello\rWorld" |
\uXXXX | Unicode character | "\u0042" → B |