write function to call a web api and parse results in json in matlab

main.m
function data = callWebAPI(url)
    % Load URL data
    options = weboptions('CertificateFilename', 'insecure.crt');
    raw_data = webread(url, options);

    % Parse JSON data
    data = jsondecode(raw_data);
end
215 chars
9 lines

The callWebAPI function takes a URL as its input and returns the parsed JSON data from the API call. The weboptions function is used to pass any required options, such as using a self-signed SSL certificate as shown above with the 'CertificateFilename' option.

The webread function is then used to load the data from the API call, and the jsondecode function is used to parse the JSON data into a matlab structure that can be easily used for further analysis.

gistlibby LogSnag