load_json()#

Load a JSON data file from a file or URL.

Examples#

example picture for load_json()
def setup():
    data = py5.load_json('colors.json')
    py5.fill(data['red'], data['green'], data['blue'])
    py5.rect(10, 10, 80, 80)
def setup():
    global promise
    py5.size(200, 100)
    promise = py5.launch_promise_thread(load_data)


def load_data():
    return py5.load_json('http://py5coding.org/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.

Signatures#

load_json(
    json_path: Union[str, Path],  # url or file path for JSON data file
    **kwargs: dict[str, Any]
) -> Any

Updated on September 04, 2022 12:55:11pm UTC