Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: create_example_json.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script creates an example JSON file ('example.json') with sample data.
- Requirements:
- - Python 3.x
- Usage:
- 1. Save this script as 'create_example_json.py'.
- 2. Run the script.
- Note: Adjust the 'json_filename' variable in the script as needed.
- """
- import json
- def create_example_json(json_filename):
- data = {
- "name": "John Doe",
- "age": 30,
- "city": "New York",
- "interests": ["reading", "traveling", "coding"]
- }
- with open(json_filename, 'w') as jsonfile:
- json.dump(data, jsonfile, indent=2)
- if __name__ == "__main__":
- # Set the filename for the example JSON file
- json_filename = 'example.json'
- # Create the example JSON file in the current working directory
- create_example_json(json_filename)
- print(f"Example JSON file '{json_filename}' created in the current working directory.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement