load_json()
Contents
load_json()¶
Load a JSON data file from a file or URL.
Examples¶

1 2 3 4 | def setup():
data = py5.load_json('colors.json')
py5.fill(data['red'], data['green'], data['blue'])
py5.rect(10, 10, 80, 80)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | def setup():
global promise
py5.size(200, 100)
promise = py5.launch_promise_thread(load_data)
def load_data():
return py5.load_json('http://py5.ixora.io/files/secret_message.json')
def draw():
py5.background(0)
if promise.is_ready:
py5.text(promise.result['msg'][:(py5.frame_count // 25)], 20, 50)
|
Description¶
Load a JSON data file from a file or URL. When loading a file, the path can be in the data directory, relative to the current working directory (sketch_path()), or an absolute path. When loading from a URL, the json_path
parameter must start with http://
or https://
.
When loading JSON data from a URL, the data is retrieved using the Python requests library with the get
method, and the kwargs
parameter is passed along to that method. When loading JSON data from a file, the data is loaded using the Python json library with the load
method, and again the kwargs
parameter passed along to that method.
Syntax¶
load_json(json_path: Union[str, Path], **kwargs: dict[str, Any]) -> Any
Parameters¶
json_path: Union[str, Path] - url or file path for JSON data file
kwargs: dict[str, Any] - keyword arguments
Updated on March 24, 2022 16:35:56pm UTC