Home > Article > Backend Development > What are the Python json types? List examples to parse Python json
There is json in any language, In this chapter we will use examples to analyze and introduce how to use Python language to code, and how to use Python languageGo to decode the JSON object.
JSON(JavaScript Object Notation) is a lightweight data exchange format that is easy for humans to read and write.
JSON function
Using JSON functionneeds to import the json library: import json.
json.dumps
##json.dumps is used to encode Python objects into JSON strings.Grammar
json.dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding="utf-8", default=None, sort_keys=False, **kw)
Examples
The following examples Encode the array into JSON format data:
#!/usr/bin/python import json data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ] json = json.dumps(data) print jsonThe execution result of the above code is:
[{"a": 1, "c": 3, "b": 2, "e": 5, "d": 4}]Use parameters to format the JSON data for output:
>>> import json >>> print json.dumps({'a': 'Runoob', 'b': 7}, sort_keys=True, indent=4, separators=(',', ': ')) { "a": "Runoob", "b": 7 }python original type Conversion table to json type:
The above is the detailed content of What are the Python json types? List examples to parse Python json. For more information, please follow other related articles on the PHP Chinese website!