| import json | |
| # Tên file đầu vào và đầu ra | |
| json_file = '1_response.json' # Thay bằng tên file json của bạn | |
| txt_file = 'output.txt' # Tên file txt bạn muốn xuất ra | |
| # Mở và đọc file JSON | |
| with open(json_file, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| # Mở file TXT để ghi | |
| with open(txt_file, 'w', encoding='utf-8') as f: | |
| for item in data: | |
| # Lấy giá trị của key "prompt" | |
| prompt_text = item.get("prompt", "") | |
| # Ghi vào file txt và thêm dấu xuống dòng | |
| if prompt_text: | |
| f.write(prompt_text + '\n\n') | |
| print(f"Đã xuất thành công các prompt ra file {txt_file}!") |