Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
import json def safe_parse(text: str) -> dict | None: try: return json.loads(text) except json.JSONDecodeError as e: print(f"Invalid JSON at line {e.lineno}, col {e.colno}: {e.msg}") return None data = safe_parse('{"key": "value"}') # OK bad = safe_parse('not json at all') # None + error message
Result
Open