json.load
Lit un fichier JSON et le transforme en objets Python (dictionnaires, listes) ; json.dump fait l'inverse.
Syntaxe
json.load(fichier) / json.dump(objet, fichier, indent=2)
Exemple
import json
with open("postes.json", encoding="utf-8") as f:
postes = json.load(f)
print(len(postes))
💡 Dans json.dump, indent=2 rend le fichier lisible et ensure_ascii=False garde les accents tels quels.
⚠️ Ouvre toujours le fichier avec encoding="utf-8". Pour un texte JSON déjà en mémoire (et non un fichier), c'est json.loads.
