19 lines
825 B
Python
19 lines
825 B
Python
import json
|
|
|
|
# Чтение данных из файла
|
|
with open('russia.geojson', 'r', encoding='utf-8') as infile:
|
|
data = json.load(infile)
|
|
|
|
# Поля, которые нужно оставить
|
|
fields_to_keep = ['id', 'name', 'full_name', 'major_cities', '_cartodb_id0', 'cartodb_id']
|
|
|
|
# Обновляем свойства в каждом объекте features
|
|
for feature in data['features']:
|
|
feature['properties'] = {key: feature['properties'][key] for key in fields_to_keep if key in feature['properties']}
|
|
|
|
# Запись резФультата в новый файл
|
|
with open('russia_2.geojson', 'w', encoding='utf-8') as outfile:
|
|
json.dump(data, outfile, ensure_ascii=False, separators=(',', ':'))
|
|
|
|
print("Обработка завершена. Результат записан в output.json.")
|