First, the object will be converted to a json string
-
: Encoding Python Objects as JSON Strings
-
: Decode encoded JSON strings into Python objects
import json data = [ { 'name' : 'autofelix', 'age' : 27}, { 'name' : 'Flying Rabbit', 'age' : 26} ] result = (data, ensure_ascii=False) print(result)
II. Formatted output
import json data = [ { 'name' : 'autofelix', 'age' : 27}, { 'name' : 'Flying Rabbit', 'age' : 26} ] # Formatted output result = (data, sort_keys=True, indent=4, separators=(',', ': ')) print(result)
Third, the json string into an object
import json data = "[{ 'name' : 'autofelix', 'age' : 27}, { 'name' : 'Flying Rabbit', 'age' : 26}]" result = (data) print(result)
IV. Install demjson
- is a third-party module library for python that can be used to encode and decode JSON data.
- Includes JSONLint formatting and checksum functions.
pip install demjson
Fifth, the object will be converted to a json string
-
encode
: Encoding Python Objects as JSON Strings -
decode
: Decode encoded JSON strings into Python objects
import demjson data = [ { 'name' : 'autofelix', 'age' : 27}, { 'name' : 'Flying Rabbit', 'age' : 26} ] result = (data) print(result)
Six, the json string into an object
import demjson data = "[{ 'name' : 'autofelix', 'age' : 27}, { 'name' : 'Flying Rabbit', 'age' : 26}]" result = (data) print(result)
to this article on the python package JSON lightweight data manipulation tutorial article is introduced to this, more related JSON lightweight data manipulation content please search for my previous articles or continue to browse the following related articles I hope that you will support me in the future more!