Created
May 22, 2024 11:52
-
-
Save mickaelandrieu/05d0e5e4718b57207ba6657b49c1594e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def tableau_vers_json(tableau): | |
""" | |
Convertit un tableau (liste de listes) en JSON. | |
:param tableau: Liste de listes à convertir | |
:return: Chaîne JSON | |
""" | |
try: | |
json_output = json.dumps(tableau) | |
return json_output | |
except (TypeError, ValueError) as e: | |
return str(e) | |
# Exemple de tableau | |
tableau = [ | |
["Nom", "Âge", "Ville"], | |
["Alice", 30, "Paris"], | |
["Bob", 25, "Lyon"], | |
["Charlie", 35, "Marseille"] | |
] | |
# Conversion du tableau en JSON | |
json_result = tableau_vers_json(tableau) | |
print(json_result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment