Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: json2html.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script converts a JSON file (.json) to an HTML file (.html).
- It reads the JSON data from the file and generates an HTML representation.
- Requirements:
- - Python 3.x
- Usage:
- 1. Save this script as 'json2html.py'.
- 2. Ensure your JSON file ('example.json') is in the same directory as the script.
- 3. Run the script.
- 4. The converted HTML file ('json2html.html') will be generated in the same directory.
- Note: Adjust the 'json_filename' and 'html_filename' variables in the script as needed.
- """
- import json
- def json_to_html(json_filename, html_filename):
- with open(json_filename, 'r') as jsonfile:
- data = json.load(jsonfile)
- html_content = "<html><body><pre>\n"
- html_content += json.dumps(data, indent=2, ensure_ascii=False)
- html_content += "\n</pre></body></html>"
- with open(html_filename, 'w') as htmlfile:
- htmlfile.write(html_content)
- if __name__ == "__main__":
- # Set the filenames for the JSON and HTML files
- json_filename = 'example.json'
- html_filename = 'json2html.html'
- # Convert the JSON file to an HTML file
- json_to_html(json_filename, html_filename)
- print(f"Converted '{json_filename}' to '{html_filename}'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement