{"id":579,"library":"simplejson","title":"Simplejson","description":"Simplejson is a fast, extensible, and standards-compliant JSON encoder/decoder for Python. It's often used as a drop-in replacement for Python's built-in `json` module, offering a C extension for improved performance and additional features. The library is actively maintained, with the current stable version being 3.20.2, and releases occur several times a year.","status":"active","version":"3.20.2","language":"python","source_language":"en","source_url":"https://github.com/simplejson/simplejson","tags":["json","serialization","deserialization","high-performance","encoding","decoding"],"install":[{"cmd":"pip install simplejson","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"While often used as a drop-in replacement, it is its own module and should be imported as 'simplejson'.","wrong":"import json; # only if you've specifically monkey-patched sys.modules['json'] = simplejson","symbol":"simplejson","correct":"import simplejson"},{"note":"'load' is for file-like objects, 'loads' is for strings.","wrong":"from simplejson import load","symbol":"loads","correct":"simplejson.loads"},{"note":"'dump' is for file-like objects, 'dumps' is for strings.","wrong":"from simplejson import dump","symbol":"dumps","correct":"simplejson.dumps"}],"quickstart":{"code":"import simplejson\n\ndata = {'name': 'Alice', 'age': 30, 'is_student': False, 'courses': ['Math', 'Science']}\n\n# Encode Python object to JSON string\njson_string = simplejson.dumps(data, indent=4)\nprint('Encoded JSON:')\nprint(json_string)\n\n# Decode JSON string to Python object\ndecoded_data = simplejson.loads(json_string)\nprint('\\nDecoded Data:')\nprint(decoded_data)\nprint(f\"Accessing a value: {decoded_data['name']}\")","lang":"python","description":"This quickstart demonstrates encoding a Python dictionary into a formatted JSON string using `simplejson.dumps` and then decoding it back into a Python object using `simplejson.loads`."},"warnings":[{"fix":"Review the `simplejson.JSONDecoder` and `simplejson.JSONEncoder` options for flags that can re-enable specific non-compliant behaviors if absolutely necessary, but it's recommended to update your JSON data to be strictly compliant.","message":"In versions 3.19.1 and later, security hardening measures changed default behavior to be more strict, consuming and producing only compliant JSON by default. If your application previously relied on non-compliant JSON features being tolerated (e.g., non-string keys if `use_decimal=True`), you might need to adjust your data or explicitly re-enable older, less strict behaviors using specific flags.","severity":"breaking","affected_versions":">=3.19.1"},{"fix":"No fix needed; this is an expected behavior for compatibility and stability on specific runtimes.","message":"simplejson disables C speedups on specific Python runtimes (e.g., PyPy, GraalPy) where they are not compatible or provide no benefit. If you are using these runtimes, expect equivalent performance to the pure-Python implementation.","severity":"gotcha","affected_versions":">=3.20.2 for GraalPy, older for PyPy"},{"fix":"Ensure that keys in objects intended for JSON serialization are inherently string-compatible or are handled explicitly. Most common use cases should not be affected.","message":"Versions 3.20.0 and 3.20.1 changed key memoization behavior to ensure keys are coerced to strings before memoization. While unlikely to cause direct breaks, if you had highly specific reliance on the internal memoization of non-string keys (e.g., custom objects used as keys that were not string-coerced until later stages), this might subtly alter behavior or performance profiles.","severity":"gotcha","affected_versions":">=3.20.0"}],"env_vars":null,"last_verified":"2026-05-12T16:16:01.155Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Provide a custom 'default' function to `simplejson.dumps()` to handle non-serializable types, or convert them to a serializable format (e.g., string for datetime) before serialization.","cause":"Python objects like datetime, sets, or custom classes are not natively convertible into standard JSON types for serialization.","error":"TypeError: Object of type datetime is not JSON serializable"},{"fix":"Ensure the input string is a well-formed JSON document before passing it to `simplejson.loads()`.","cause":"The input string is not valid JSON, often because it's empty, malformed, or contains non-JSON content at the beginning.","error":"simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)"},{"fix":"Install the 'simplejson' package using pip: `pip install simplejson`.","cause":"The 'simplejson' package is not installed in the Python environment where the script is being executed.","error":"ImportError: No module named 'simplejson'"},{"fix":"If you want a JSON string, use `simplejson.dumps()`. If writing to a file, provide a file object as the second argument to `simplejson.dump()`.","cause":"Attempting to use `simplejson.dump` (which writes to a file-like object) when `simplejson.dumps` (which returns a JSON string) was intended, or misunderstanding the function signature.","error":"AttributeError: module 'simplejson' has no attribute 'dump'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"4.1.1","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"18.6M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"18.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.7,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"20.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"20.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.8,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"21M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"12.4M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"12.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"13M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.5,"disk_size":"12.2M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.5,"disk_size":"11.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"13M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"18.1M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"18.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"19M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}