# Defining JSONArray with name but without array

**URL:** <https://discourse.processing.org/t/defining-jsonarray-with-name-but-without-array/37822>\
**Category:** Beginners\
**Created:** [July 4, 2022, 7:39am UTC](https://discourse.processing.org/t/defining-jsonarray-with-name-but-without-array/37822 "2022-07-04T07:39:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruchi](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ruchi](https://discourse.processing.org/u/Ruchi)\
**Post date:** [July 4, 2022, 7:39am UTC](https://discourse.processing.org/t/defining-jsonarray-with-name-but-without-array/37822/1 "2022-07-04T07:39:18Z")

</div>

I am trying to define a JSONArray within a JSON object but I will be adding objects in array later.  
So when declaring it , I cannot use setJSONArray function.  
How can I retrieve it by getJSONArray function if I have not  
named it.  
Is there a way to declare JSONArray with name and append in it later?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 4, 2022, 8:47am UTC](https://discourse.processing.org/t/defining-jsonarray-with-name-but-without-array/37822/2 "2022-07-04T08:47:22Z")

</div>

> [@Ruchi](#):
>
> So when declaring it, I cannot use **setJSONArray()** function.  
> How can I retrieve it by **getJSONArray()** function if I have not named it?

Both methods [JSONObject](https://processing.org/reference/JSONObject.html)::[**setJSONArray()**](https://processing.org/reference/JSONObject_setJSONArray_.html) & [JSONObject](https://processing.org/reference/JSONObject.html)::[**getJSONArray()**](https://processing.org/reference/JSONObject_getJSONArray_.html) require a named key parameter as their 1st passed argument.

> [@Ruchi](#):
>
> I am trying to define a JSONArray within a JSONObject, but I’ll be adding objects in the array later.

> [@Ruchi](#):
>
> Is there a way to declare JSONArray with name and **append()** in it later?

B/c every time we add a `new` [JSONArray](https://processing.org/reference/JSONArray.html) object to an existing [JSONObject](https://processing.org/reference/JSONObject.html) via its method [**setJSONArray()**](https://processing.org/reference/JSONObject_setJSONArray_.html) we must pass a String as the 1st argument, that [JSONArray](https://processing.org/reference/JSONArray.html) will surely have a named property key within that [JSONObject](https://processing.org/reference/JSONObject.html).

Once you access that [JSONArray](https://processing.org/reference/JSONArray.html) later via method [JSONObject](https://processing.org/reference/JSONObject.html)::[**getJSONArray()**](https://processing.org/reference/JSONObject_getJSONArray_.html) you’ll be able to add any kind of valid JSON values to it via its method [JSONArray](https://processing.org/reference/JSONArray.html)::[**append()**](https://processing.org/reference/JSONArray_append_.html), including even other [JSONObject](https://processing.org/reference/JSONObject.html) objects:

[Processing.GitHub.io/processing-javadocs/core/processing/data/JSONArray.html#append-processing.data.JSONObject-](http://Processing.GitHub.io/processing-javadocs/core/processing/data/JSONArray.html#append-processing.data.JSONObject-)
