Answers for "convert dictionary list to json python"

4

python dict into json string

import json   
# Data to be written
dictionary ={   
  "A": 5,   
  "B": "guys",   
}

# Serializing json
json_object = json.dumps(dictionary, indent = 4)   
print(json_object)
# Output
{
    "A": 5,
    "B": "guys",
}
Posted by: Guest on July-18-2020
4

save a dict to json python

import json

with open('data.json', 'w') as fp:
    json.dump(data, fp)
Posted by: Guest on August-26-2020
0

write list of dictionaries to json python

def filewriter(line):
    dictionary = {}
    dictionary['name'] = line[0][0] #assume this is a a string
    dictionary['item_to_buy'] = line[0][1]
    dictionary['currency'] = line[0][2]
    dictionary['league'] = line[0][3]
    with open('logs.json', 'r+') as f:
        if len(f.read()) == 0:
            f.write(json.dumps(dictionary))
        else:
            f.write(',\n' + json.dumps(dictionary))

def retrieve():
    with open('logs.json') as f:
        g = json.load(f)
        print(g[1]['name'])
Posted by: Guest on November-30-2019

Code answers related to "convert dictionary list to json python"

Code answers related to "Javascript"

Browse Popular Code Answers by Language