Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: json2txt.py
- # Author: Jeoi Reqi
- """
- JSON to Text Converter
- This Python script converts the contents of a JSON file into plain text and saves the result in a text file.
- The output text file is formatted with indentation for better readability.
- Usage:
- 1. Ensure you have Python 3 installed.
- 2. Replace 'input.json' and 'output.txt' with your actual JSON input file and desired text output file names.
- 3. Run the script, and the converted text will be saved in the specified output file.
- Requirements:
- - Python 3
- Example Usage:
- python json2txt.py
- """
- import json
- import os
- def json_to_text(input_json_file, output_text_file):
- input_json_path = os.path.join(os.getcwd(), input_json_file)
- output_text_path = os.path.join(os.getcwd(), output_text_file)
- with open(input_json_path, 'r', encoding='utf-8') as json_file:
- data = json.load(json_file)
- with open(output_text_path, 'w', encoding='utf-8') as text_file:
- text_file.write(json.dumps(data, indent=2, ensure_ascii=False))
- # Replace 'input.json' and 'output.txt' with your actual file names
- json_to_text('input.json', 'output.txt')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement