Skip to content

json.decoder.JSONDecodeError: Expecting value

Error message

                Expecting value: line 1 column 1 (char 0)
              

Quick summary

You tried to parse a string as JSON, but the string isn't valid JSON format.

Why this happens

  • Malformed JSON — missing quotes, brackets, or commas

  • Empty string passed to json.loads()

  • JSON with trailing commas (not allowed in JSON)

  • Single quotes instead of double quotes (JSON requires double quotes)

Minimal example

✗ Broken code
import json
data = json.loads("{name: 'Alice'}")  # JSONDecodeError — invalid JSON
✓ Fixed code
import json
try:
    data = json.loads('{"name": "Alice"}')  # Valid JSON
    print(data)
except json.JSONDecodeError as e:
    print(f"Invalid JSON: {e}")

JSON requires double quotes for strings and keys. The fixed version uses valid JSON syntax.

How to diagnose

  • Validate the JSON string with a JSON linter

  • Print the string to see what's wrong

  • Check for common issues: single quotes, trailing commas, missing braces

How to fix

  • Fix the JSON string to be valid JSON

  • Use try/except json.JSONDecodeError to handle parse errors

  • Validate JSON before parsing with a linter

How to prevent

  • Always use json.dumps() to create JSON (never build strings manually)

  • Validate JSON input before parsing

  • Use try/except around json.loads() for external data

Related Resources

Related Glossary

Related Lessons

Related Practice

← Back to language