save_json()#

Save JSON data to a file.

Examples#

data = dict(mouse_x=[], mouse_y=[])

def draw():
    py5.point(py5.mouse_x, py5.mouse_y)
    if py5.frame_count % 60 == 0:
        data['mouse_x'].append(py5.mouse_x)
        data['mouse_y'].append(py5.mouse_y)
    if py5.frame_count == 600:
        py5.save_json(data, 'data/mouse_positions.json')
        py5.exit_sketch()

Description#

Save JSON data to a file. If filename is not an absolute path, it will be saved relative to the current working directory (sketch_path()).

The JSON data is saved using the Python json library with the dump method, and the kwargs parameter is passed along to that method.

Signatures#

save_json(
    json_data: Any,  # json data object
    filename: Union[str, Path],  # filename to save JSON data object to
    **kwargs: dict[str, Any]
) -> None

Updated on September 01, 2022 16:36:02pm UTC