# Potential JSONObject bug?

**URL:** <https://discourse.processing.org/t/potential-jsonobject-bug/5930>\
**Category:** Coding Questions\
**Created:** [November 25, 2018, 5:29pm UTC](https://discourse.processing.org/t/potential-jsonobject-bug/5930 "2018-11-25T17:29:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RecursiveCursive](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@RecursiveCursive](https://discourse.processing.org/u/RecursiveCursive)\
**Post date:** [November 25, 2018, 5:29pm UTC](https://discourse.processing.org/t/potential-jsonobject-bug/5930/1 "2018-11-25T17:29:49Z")

</div>

My project makes use of JSON to store user data, but I am having a strange issue with it. One of my methods is a delete method that is supposed to delete saved data and replace it with a single entry indicating no saved data in that slot.

```auto
public void deleteSave(int id) {
	// Delete the save with the given ID.
	allSaves.setJSONObject(id - 1, emptySave);
	writeSave(); // Calls a function that executes a "saveJSONArray()"
	System.out.println(emptySave);
}

```

The issue that I am having is that somehow, the emtpySave JSONObject gets changed to have the contents of what was just erased stored in it even though I never requested such a change to occur. This results in future deletions not working since the data that is now stored in it it just being written in place. Does anyone have any idea what is going on? I am using Processing 2.2.1.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [November 26, 2018, 3:30am UTC](https://discourse.processing.org/t/potential-jsonobject-bug/5930/2 "2018-11-26T03:30:30Z")

</div>

Can you please post a complete example that we can copy and paste to see the error?

---

<div class="post-metadata">

**Author:** ![RecursiveCursive](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@RecursiveCursive](https://discourse.processing.org/u/RecursiveCursive)\
**Post date:** [December 7, 2018, 7:37pm UTC](https://discourse.processing.org/t/potential-jsonobject-bug/5930/3 "2018-12-07T19:37:55Z")

</div>

I was able to identify the issue. Apparently when I wrote the code for this section of my program, I allowed myself to forget that setting an object variable equal to another object variable does not create a copy of it, but they point to the same thing. I went back and rewrote my code to not include this oversight and it now works as it should.
