INI zu JSON
INI-Konfigurationsdateien in JSON umwandeln und umgekehrt.
HĂ€ufig gestellte Fragen
Code-Implementierung
import configparser
import json
def ini_to_json(ini_text: str) -> dict:
config = configparser.ConfigParser()
config.read_string(ini_text)
result = {}
for section in config.sections():
result[section] = dict(config[section])
# Top-level keys (DEFAULT section workaround)
for key, value in config.defaults().items():
result[key] = value
return result
ini_text = """
[database]
host = localhost
port = 5432
name = mydb
"""
data = ini_to_json(ini_text)
print(json.dumps(data, indent=2))Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.