Decodes a JSON-encoded string into a Python object. == Optional arguments == * 'encoding' (string, default None) This argument provides a hint regarding the character encoding that the input text is assumed to be in (if it is not already a unicode string type).
( txt, encoding=None, **kwargs )
| 5443 | |
| 5444 | |
| 5445 | def decode( txt, encoding=None, **kwargs ): |
| 5446 | """Decodes a JSON-encoded string into a Python object. |
| 5447 | |
| 5448 | == Optional arguments == |
| 5449 | |
| 5450 | * 'encoding' (string, default None) |
| 5451 | |
| 5452 | This argument provides a hint regarding the character encoding |
| 5453 | that the input text is assumed to be in (if it is not already a |
| 5454 | unicode string type). |
| 5455 | |
| 5456 | If set to None then autodetection of the encoding is attempted |
| 5457 | (see discussion above). Otherwise this argument should be the |
| 5458 | name of a registered codec (see the standard 'codecs' module). |
| 5459 | |
| 5460 | * 'strict' (Boolean, default False) |
| 5461 | |
| 5462 | If 'strict' is set to True, then those strings that are not |
| 5463 | entirely strictly conforming to JSON will result in a |
| 5464 | JSONDecodeError exception. |
| 5465 | |
| 5466 | * 'return_errors' (Boolean, default False) |
| 5467 | |
| 5468 | Controls the return value from this function. If False, then |
| 5469 | only the Python equivalent object is returned on success, or |
| 5470 | an error will be raised as an exception. |
| 5471 | |
| 5472 | If True then a 2-tuple is returned: (object, error_list). The |
| 5473 | error_list will be an empty list [] if the decoding was |
| 5474 | successful, otherwise it will be a list of all the errors |
| 5475 | encountered. Note that it is possible for an object to be |
| 5476 | returned even if errors were encountered. |
| 5477 | |
| 5478 | * 'return_stats' (Boolean, default False) |
| 5479 | |
| 5480 | Controls whether statistics about the decoded JSON document |
| 5481 | are returns (and instance of decode_statistics). |
| 5482 | |
| 5483 | If True, then the stats object will be added to the end of the |
| 5484 | tuple returned. If return_errors is also set then a 3-tuple |
| 5485 | is returned, otherwise a 2-tuple is returned. |
| 5486 | |
| 5487 | * 'write_errors' (Boolean OR File-like object, default False) |
| 5488 | |
| 5489 | Controls what to do with errors. |
| 5490 | |
| 5491 | - If False, then the first decoding error is raised as an exception. |
| 5492 | - If True, then errors will be printed out to sys.stderr. |
| 5493 | - If a File-like object, then errors will be printed to that file. |
| 5494 | |
| 5495 | The write_errors and return_errors arguments can be set |
| 5496 | independently. |
| 5497 | |
| 5498 | * 'filename_for_errors' (string or None) |
| 5499 | |
| 5500 | Provides a filename to be used when writting error messages. |
| 5501 | |
| 5502 | * 'allow_xxx', 'warn_xxx', and 'forbid_xxx' (Booleans) |
no test coverage detected
searching dependent graphs…