JSON decode without writing a script
When you meet an encoded JSON value in a log or a database, the usual way to read it is a quick json_decode in PHP or json.loads in Python. This JSON decode tool does the same job in the browser: paste the string, and the decoded document appears with indentation you choose.
Example: output of PHP json_encode
PHP escapes slashes and non-ASCII characters by default, so an encoded payload may look like this:
"{\"url\":\"https:\/\/example.com\/a\",\"city\":\"M\u00fcnchen\"}"
Decoding gives the real characters back:
{
"url": "https://example.com/a",
"city": "München"
}
Differences from json_decode and json.loads
- Layers are unwrapped for you. In PHP,
json_decode('"{\"a\":1}"')returns the string{"a":1}, and you need a second call to get the array. This page keeps decoding while the result is still a JSON-looking string, so double-encoded values come out as objects. - Missing outer quotes are tolerated. Text such as
{\"a\":1}, which is not a valid literal on its own, is still decoded. - Errors are explained.
json_decodereturnsnulland leaves you to calljson_last_error_msg(). Here the status bar names the problem and its position.
Invalid values you may see
Encoded strings produced by hand or by non-JSON serializers often contain values that JSON does not allow. They are reported with line and column in the decoded text:
| Inside the decoded JSON | Message |
|---|---|
True, False, None | Literals must be lowercase: true, false, null |
undefined | 'undefined' is not a valid JSON value |
NaN, Infinity | NaN and Infinity are not valid JSON numbers |
| A trailing comma | Trailing comma before '}' is not allowed |
A Python str() of a dictionary is a frequent culprit: it writes single-quoted keys as well as True and None. Generate the value with json.dumps instead, or clean it up with the JSON fixer.
Output and the Encode button
The decoded JSON is printed with the Indent you pick: 2, 3 or 4 spaces or a tab. Key order and values are kept exactly as they were in the string. Encode runs the reverse step, compacting the JSON in the input and escaping it into one string, so you can edit a decoded payload and put it back.
Related tools
For decoding values that have been Base64-encoded rather than string-escaped, use Base64 to JSON. If the decoded data is large, open it in the JSON viewer to browse it as a tree.
Decoding happens locally in your browser; the string you paste is not sent anywhere, except when you choose Load URL or Save & Share.
JSON decode in Python and JSONDecodeError
json.loads() decodes a JSON string into dictionaries, lists, strings, numbers, True, False and None; json.load() does the same for an open file. Text that is not valid JSON raises json.JSONDecodeError, and the message says more than it seems to. Expecting value at line 1, column 1 means the string is empty or is not JSON at all, for example an HTML error page returned in place of an API response. Expecting property name enclosed in double quotes points to single quotes or a trailing comma, and Extra data means a second document follows the first.
import json
text = '{"user": {"id": 7, "name": "Sara", "roles": ["admin", "editor"]}, "expires": 3600}'
data = json.loads(text) # JSON text -> dict
print(data["user"]["roles"][0]) # admin
samples = ["", "{'id': 7}", '{"id": 7,}', '{"ok": True}', '{"a": 1} {"b": 2}']
for bad in samples:
try:
json.loads(bad)
except json.JSONDecodeError as e:
print(f"{bad!r}: {e.msg} (line {e.lineno}, column {e.colno})")
Paste the failing text above to see the same problem described in plainer words, or send it through the JSON fixer when it is almost valid.