Advertisement
Python253

create_example_json

Mar 12th, 2024
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: create_example_json.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6. # For use with 'parity_number_counter.py': https://pastebin.com/KcCdq19X
  7.  
  8. """
  9. Description:
  10. This script creates an example JSON file ('example.json') with sample data.
  11.  
  12. Requirements:
  13. - Python 3.x
  14.  
  15. Usage:
  16. 1. Save this script as 'create_example_json.py'.
  17. 2. Run the script.
  18.  
  19. Note: Adjust the 'json_filename' variable in the script as needed.
  20. """
  21. import json
  22.  
  23. def create_example_json(json_filename):
  24.     people_data = [
  25.         {
  26.             "name": "John Doe",
  27.             "age": 30,
  28.             "city": "New York",
  29.             "interests": ["reading", "traveling", "coding"],
  30.             "salary": 75000.50,
  31.             "experience_years": 5,
  32.             "height_cm": 180,
  33.             "weight_kg": 75.5,
  34.             "savings": 120000.75,
  35.             "days_of_vacation": 20,
  36.             "average_speed_kmph": 45.5
  37.         },
  38.         {
  39.             "name": "Jane Smith",
  40.             "age": 25,
  41.             "city": "Los Angeles",
  42.             "interests": ["hiking", "photography", "music"],
  43.             "salary": 65000.75,
  44.             "experience_years": 3,
  45.             "height_cm": 165,
  46.             "weight_kg": 60.2,
  47.             "savings": 95000.20,
  48.             "days_of_vacation": 15,
  49.             "average_speed_kmph": 40.0
  50.         },
  51.         # Add more people as needed
  52.     ]
  53.  
  54.     with open(json_filename, 'w') as jsonfile:
  55.         json.dump(people_data, jsonfile, indent=2)
  56.  
  57. if __name__ == "__main__":
  58.     # Set the filename for the example JSON file
  59.     json_filename = 'example.json'
  60.    
  61.     # Create the example JSON file in the current working directory
  62.     create_example_json(json_filename)
  63.  
  64.     print(f"Example JSON file '{json_filename}' created in the current working directory.")
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement