Outils pour utilisateurs

Outils du site


python:json

Ceci est une ancienne révision du document !


Table des matières

JSON

Encodage

import json
 
data = [
     'foo',
     {
         'bar': ('baz', None, 1.0, 2)
     }
]
 
j = json.dumps(data)

Avec indentation :

j = json.dumps(data, indent=4)
print(j)

Décodage

Depuis une chaîne :

import json
 
data = json.loads(str)

Depuis un fichier :

import json
 
file_path = "/home/marc/fichier_json.dat"
 
with open(save_path, 'r') as f:
    data = json.load(f)
python/json.1607850266.txt.gz · Dernière modification: 2020/12/13 09:04 par marclebrun