At first you becameDictionary format
data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]
import json data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ] data2 = (data) print(data2)
(data) is to json the array.
json format output
data2 = ({'a': 'Runoob', 'b': 7}, sort_keys=True, indent=4, separators=(',', ': '))
json append data
Idea: Add new data to dict first
#Add data## Method 1print("-----------------") data[0]['f'] = 6 data4 = (data, sort_keys=True, indent=4, separators=(',', ': ')) print(data4) print("-----------------") ## Method 2data[0].setdefault('g',7) data5 = (data, sort_keys=True, indent=4, separators=(',', ': ')) print(data5)
This is the end of this article about the implementation of python dict conversion to json format. For more related content of python dict conversion to json, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!