save_json()#

Save JSON data to a file.

Examples#

 1data = dict(mouse_x=[], mouse_y=[])
 2
 3def draw():
 4    py5.point(py5.mouse_x, py5.mouse_y)
 5    if py5.frame_count % 60 == 0:
 6        data['mouse_x'].append(py5.mouse_x)
 7        data['mouse_y'].append(py5.mouse_y)
 8    if py5.frame_count == 600:
 9        py5.save_json(data, 'data/mouse_positions.json')
10        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.

Syntax#

save_json(json_data: Any, filename: Union[str, Path], **kwargs: dict[str, Any]) -> None

Parameters#

  • filename: Union[str, Path] - filename to save JSON data object to

  • json_data: Any - json data object

  • kwargs: dict[str, Any] - keyword arguments

Updated on March 01, 2022 12:15:01pm UTC