FormatterHQ

JSON Decode Online

Decode an encoded JSON string into formatted JSON, like json_decode in PHP or json.loads in Python, and see exactly where decoding fails when the data is invalid.

Input TEXT
Output JSON
Ready.

How to use the JSON Decode Online

  1. Paste the encoded string, for example a value copied from a PHP or Python program, or click Sample.
  2. Choose the Indent for the decoded output.
  3. Click Decode. Use Encode to turn JSON back into an escaped string.
  4. Read any error in the status bar, fix the input and copy the decoded JSON.

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_decode returns null and leaves you to call json_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 JSONMessage
True, False, NoneLiterals must be lowercase: true, false, null
undefined'undefined' is not a valid JSON value
NaN, InfinityNaN and Infinity are not valid JSON numbers
A trailing commaTrailing 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.

Frequently asked questions

What is the difference between json_decode and this tool?
Both turn an encoded JSON string into data. This page also unwraps double-encoded values, accepts strings without outer quotes and reports the position of any error, and it shows the result as formatted JSON instead of a PHP array.
Why does decoding fail on True or None?
Those are Python literals. JSON only accepts lowercase true, false and null, so the decoder stops and shows the line and column of the first one it finds.
Can I decode a JSON string that uses single quotes?
Yes. A literal wrapped in single quotes, such as one copied from JavaScript or PHP code, is converted to a double-quoted string and decoded. Escaped apostrophes inside it are handled.
Will decoding change numbers or key order?
Key order is kept. Numbers are parsed as JavaScript doubles, so integers above 9,007,199,254,740,991 lose precision; keep such IDs as strings.

Last updated October 3, 2026

Related tools

JSON Deserialize Online Deserialize an escaped JSON payload into formatted JSON, then map it to typed objects in JavaScript, Python, Java or C# safely. JSON Encode Online JSON encode text or a document into an escaped string, with each escaping rule explained and the json_encode flags that give identical output. JSON Serialize Online Serialize JSON into its most compact transport form, optionally wrapped as an escaped string literal for storage or messaging. JSON Stringify Online Stringify JSON into an escaped string literal, exactly like JSON.stringify. Ready to embed JSON inside JSON, code or config values. JSON URL Decode Decode a URL-encoded JSON string back into readable JSON and pretty-print it. Base32 Decode Decode Base32 strings back to text. Padding is optional and lowercase input is accepted. JSON Editor Edit JSON online with a live tree preview, instant validation and one-click formatting, repair and minification. JSON Fixer & Repair Fix broken JSON automatically: add missing quotes, commas and brackets, remove comments and trailing commas, and convert Python literals. JSON Flatten Flatten nested JSON into single-level key paths like user.address.city, with dot, custom or bracket notation for arrays. JSON Formatter Format, beautify and validate JSON online. Pretty print minified JSON with 2, 3, 4 space or tab indentation and pinpoint syntax errors. JSON Merge Patch (RFC 7396) Apply an RFC 7396 JSON Merge Patch to a document, or create the merge patch that turns one JSON document into another. JSON Minify Minify JSON by removing whitespace and line breaks. Shrink payloads for APIs, storage and embedding, and see the bytes saved.