Tools, FAQ, Tutorials:
json.loads() - Loading JSON into Object
How to load (or decode, deserialize) a JSON string into a Python object using json.loads()?
✍: FYIcenter.com
The json.loads() function allows you to load (or decode, deserialize)
JSON strings (str, bytes or bytearray types) into Pythong objects:
json.loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)¶
The json.dumps() functions uses the following default encoding table:
JSON Type Python Type --------- ----------- object dict array list string str number (int) int number (real) float true True false False null None
Some examples on using the json.loads() function:
>>> import json
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
['foo', {'bar': ['baz', None, 1.0, 2]}]
>>> json.loads('"\\"foo\\bar"')
'"foo\x08ar'
If you try to load a string that is not a valid JSON string, you will get a json.decoder.JSONDecodeError:
>>> import json
>>> json.loads('{"1":3,"bar":foo,}')
Traceback (most recent call last):
File "...\Python36-32\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
...
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 14 (char 13)
⇒ json.tool - JSON Pretty-Print Tool
⇐ Extending json.JSONEncoder Class
2018-10-08, ∼3800🔥, 0💬
Popular Posts:
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...
How To Truncate an Array in PHP? If you want to remove a chunk of values from an array, you can use ...
How to add an API to an API product for internal testing on the Publisher Portal of an Azure API Man...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...
What is EPUB 2.0 Metadata "dc:creator" and "dc:contributor" elements? EPUB 2.0 Metadata "dc:creator"...