# Reloading a JSON in p5

**URL:** <https://discourse.processing.org/t/reloading-a-json-in-p5/15520>\
**Category:** Libraries\
**Created:** [November 16, 2019, 4:47am UTC](https://discourse.processing.org/t/reloading-a-json-in-p5/15520 "2019-11-16T04:47:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdsu2020](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@sdsu2020](https://discourse.processing.org/u/sdsu2020)\
**Post date:** [November 16, 2019, 4:47am UTC](https://discourse.processing.org/t/reloading-a-json-in-p5/15520/1 "2019-11-16T04:47:31Z")

</div>

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

```auto
function setup(){
  canvas = createCanvas(840,840); 
  myMap = mappa.tileMap(options); 
  myMap.overlay(canvas);
  myMap.onChange(drawPoint); 
  myMap.onChange(drawLine);
  url = lapi+lApiKey+format+county;
  ljson = loadJSON(url); //this starts as an empty object
  noLoop();
}

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);
//setup();
}

```

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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 16, 2019, 12:11pm UTC](https://discourse.processing.org/t/reloading-a-json-in-p5/15520/2 "2019-11-16T12:11:35Z")

</div>

you might read again  
[https://p5js.org/reference/#/p5/loadJSON](https://p5js.org/reference/#/p5/loadJSON)  
there is a second example with callback function.  
and try my test:  
[https://editor.p5js.org/kll/sketches/QpZ6AtD4a](https://editor.p5js.org/kll/sketches/QpZ6AtD4a)

---

<div class="post-metadata">

**Author:** ![sdsu2020](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@sdsu2020](https://discourse.processing.org/u/sdsu2020)\
**Post date:** [November 18, 2019, 6:41am UTC](https://discourse.processing.org/t/reloading-a-json-in-p5/15520/3 "2019-11-18T06:41:11Z")

</div>

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