Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

json_writer.py 510 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  1. import json
  2. import os
  3. def add_data_to_json(data_dict, file_path):
  4. if os.path.exists(file_path):
  5. with open(file_path, 'r') as json_file:
  6. try:
  7. existing_data = json.load(json_file)
  8. except json.JSONDecodeError:
  9. existing_data = {}
  10. else:
  11. existing_data = {}
  12. for key, value in data_dict.items():
  13. existing_data[key] = value
  14. with open(file_path, 'w') as json_file:
  15. json.dump(existing_data, json_file, indent=2)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...