---
# System prepended metadata

title: JSON TO TEXT
tags: [Script]

---

#### Script to generate questions from JSON to text format

```
import json
import os


def read_json_file():
    with open("questions.json", "r") as json_file:
        data = json.load(json_file)
        return data


def write_md_file(data):
    with open("questions.md", "w") as md_file:
        for i in range(len(data)):
            md_file.write(f"## Question {i+1}\n")
            md_file.write(f"### Question Text\n")
            md_file.write(f"{data[i]['question_text']}\n")
            md_file.write(f"### Code\n")
            md_file.write(f"{data[i]['code_metadata'][0]['code_data']}\n")
            md_file.write(f"### Options\n")
            for j in range(len(data[i]['input_output'][0]['wrong_answers'])):
                md_file.write(f"{data[i]['input_output'][0]['wrong_answers'][j]}\n")
            md_file.write(f"{data[i]['input_output'][0]['output'][0]}\n")
            md_file.write(f"### Answer\n")
            md_file.write(f"{data[i]['input_output'][0]['output'][0]}\n")
            md_file.write("\n")

            

if __name__ == "__main__":
    data = read_json_file()
    write_md_file(data)
```