Reloading a JSON in p5

Hello. I’m currently working with geocoding API with Mapquest. I have this code written in setup right now.

function setup(){
  canvas = createCanvas(840,840); 
  myMap = mappa.tileMap(options); 
  url = lapi+lApiKey+format+county;
  ljson = loadJSON(url); //this starts as an empty object

The next step I want to take is to save this JSON data into a variable so it continues to display on the map. Then I want to update the url to have it look for a new county. 
I do have this code completed here: 

function mouseClicked() {
  // print(ljson);
  county = mjson[13][5];
  county = county.replace(' ', '+');
  county = county.split(',').join('+');
  county = county.replace(' ', '');
   url = lapi+lApiKey+format+county;
  ljson = loadJSON(url);

However, what happens here is that ljson becomes an empty object. I have tried calling setup() again to no effect. My goal is that once that is updated, then I want to reload this new JSON. I know I could do this with multiple variables (having many separate urls) but I was wondering if there was a way to reload the JSON within the code.

1 Like

you might read again
there is a second example with callback function.
and try my test:

1 Like

Your example helped a lot! I am able to load my two Jsons smoothly now.

1 Like