import json
# 1. JSON 파일 읽기
file_path = 'data.json' # 여기에 파일 경로를 넣으세요
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
# 2. 특정 필드 값만 추출 (예: 'name' 필드)
# 데이터가 리스트 형태라면 반복문을 사용해야 합니다.
target_field = "name"
if isinstance(data, list):
# 리스트인 경우 모든 항목에서 해당 필드 추출
result = [item.get(target_field) for item in data if target_field in item]
else:
# 단일 객체인 경우
result = data.get(target_field, "필드를 찾을 수 없습니다.")
# 3. 결과 출력 및 저장 (ensure_ascii=False 가 한글 변환의 핵심!)
print(f"추출된 값: {result}")
with open('result.json', 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=4)
print("변환 및 저장이 완료되었습니다.")