Backend/Python

배열을 JSON으로 변경

Mr.6_냥아치 2023. 12. 13. 18:20
반응형
import json

def array_to_json_file(array, file_path):
    """
    Converts an array to a JSON file.

    :param array: List to be converted to JSON.
    :param file_path: Path where the JSON file will be saved.
    """
    # Convert the array to JSON format
    json_data = json.dumps(array, ensure_ascii=False, indent=4)

    # Write the JSON data to a file
    with open(file_path, "w", encoding="utf-8") as file:
        file.write(json_data)

# Example usage
array = #배열입력
file_path = "d:/test.json" #경로 지정

# Convert and save the array as a JSON file
array_to_json_file(array, file_path);
반응형