← Retour à la référence Python

()

Module : json

Écrit un objet Python dans un fichier au format JSON.

📝 Syntaxe

json.dump(obj, fichier)

⚙️ Paramètres

obj

Objet Python à écrire

fichier

Objet fichier ouvert en écriture

💡 Exemples

import json
data = {'nom': 'Alice', 'age': 17}
with open('data.json', 'w') as f:
    json.dump(data, f)
Écriture du JSON dans le fichier data.json
EdTech AI