Introduction
JSON (JavaScript Object Notation) is frequently used between a server and a web application. An example of JSON data:
JSON (JavaScript Object Notation) is frequently used between a server and a web application. An example of JSON data:
The json module enables you to convert between JSON and Python Objects.
JSON conversion examples
Convert JSON to Python Object (float)
Floating points can be mapped using the decimal library.
Floating points can be mapped using the decimal library.
Convert JSON to Python Object (Example)
JSON data often holds multiple objects, an example of how to use that below:
JSON data often holds multiple objects, an example of how to use that below:
Convert Python Object (Dict) to JSON
If you want to convert a Python Object to JSON use the json.dumps() method.
If you want to convert a Python Object to JSON use the json.dumps() method.
Converting JSON data to Python objects
JSON data can be converted (deserialized) to Pyhon objects using the json.loads()function. A table of the mapping:
JSON data can be converted (deserialized) to Pyhon objects using the json.loads()function. A table of the mapping:
JSON | Python |
---|---|
object | dict |
array | list |
string | str |
number (int) | int |
number (real) | float |
true | True |
false | False |
null | None |
Pretty printing
If you want to display JSON data you can use the json.dumps() function.
https://pythonspot.com/en/json-encoding-and-decoding-with-python/
No hay comentarios:
Publicar un comentario