Skip to content

Instantly share code, notes, and snippets.

@pank-su
Last active June 21, 2022 10:26
Show Gist options
  • Save pank-su/f896c22cb28a63d3d49126328d6124cd to your computer and use it in GitHub Desktop.
Save pank-su/f896c22cb28a63d3d49126328d6124cd to your computer and use it in GitHub Desktop.
Simple function, which translate json to qml ListModel file
def json_to_qml_model(json_array: list, filename: str):
with open(filename, "w", encoding="utf-8") as topic_model_file:
topic_model_file.write("""import QtQuick 2.0\n
ListModel {\n""")
for obj in json_array:
topic_model_file.write(" ListElement {\n")
[topic_model_file.write(f""" {key}: {repr(value)}\n""")
for key, value in obj.items()]
topic_model_file.write(" }\n")
topic_model_file.write("}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment