Skip to content

Instantly share code, notes, and snippets.

@mickaelandrieu
Created May 22, 2024 11:52
Show Gist options
  • Save mickaelandrieu/05d0e5e4718b57207ba6657b49c1594e to your computer and use it in GitHub Desktop.
Save mickaelandrieu/05d0e5e4718b57207ba6657b49c1594e to your computer and use it in GitHub Desktop.
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