On this page
json.JSONDecodeError
Prev: json.dumps | Up: json | Next: json.JSONDecoder
Rel: json.dump, json.dumps, json.JSONDecoder, json.JSONEncoder
Ref: docs.python.org โ json.JSONDecodeError
Tags: #public #python3 #stdlib #json
Import
import json
from json import JSONDecodeError
Signature & Overview
json.JSONDecodeError(msg, doc, pos)
Subclass of ValueError with the following additional properties: msg: The unformatted error message doc: The JSON document being parsed
Methods & Attributes
JSONDecodeError.add_note(self, note, /)โ Add a note to the exceptionJSONDecodeError.with_traceback(self, tb, /)โ Set self.traceback to tb and return self.
Usage
import json
try:
json.loads('{"a": 1,}')
except json.JSONDecodeError as exc:
assert exc.lineno == 1
assert exc.colno == 9
assert "property name" in exc.msg
Gotchas
- Subclass of
ValueError: Code catchingValueErrorwill also catchJSONDecodeError. - Rich location attributes: Inspect
exc.msg,exc.lineno,exc.colno, andexc.pos(character offset) for precise error reporting.
REPL Inspect
from json import JSONDecodeError
help(JSONDecodeError)
Linked from
Related notes
- tuts/python3/stdlib_module/json/dump Linked here; links to this page; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/dumps Linked here; links to this page; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/JSONDecoder Linked here; links to this page; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/JSONEncoder Linked here; links to this page; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/json/load links to this page; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/loads links to this page; shared tags: #json, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib