“Edit file json python” Kode Jawaban

Edit file json python

import json

with open('data.json', 'r+') as f:
    data = json.load(f)
    data['id'] = 134 # <--- add `id` value.
    f.seek(0)        # <--- should reset file position to the beginning.
    json.dump(data, f, indent=4)
    f.truncate()     # remove remaining part
TheProgrammer

masukkan file json dalam python

a_dictionary = {"d": 4}

with open("sample_file.json", "r+") as file:
    data = json.load(file)	# get data from file
    update(a_dictionary)
    seek(0)
    json.dump(data, file)	# insert data in file
Nickton

Jawaban yang mirip dengan “Edit file json python”

Pertanyaan yang mirip dengan “Edit file json python”

Lebih banyak jawaban terkait untuk “Edit file json python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya