save_json()

Save JSON data to a file.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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.

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 September 11, 2021 16:51:34pm UTC