i not say it is wrong way, but i look at 2 examples,
and they work with
json = loadJSONObject(url+query+"&page="+page+beginDate+endDate+"&api-key="+apiKey);
or
loadJSON(url,gotData); // callback version
so pls check on
https://processing.org/reference/loadJSONObject_.html