# Getting the correct object array from an API JSON input

**URL:** <https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685>\
**Category:** Issues / Bugs\
**Created:** [March 12, 2023, 11:45pm UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685 "2023-03-12T23:45:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [March 12, 2023, 11:45pm UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/1 "2023-03-12T23:45:33Z")

</div>

Hey, I am trying to get the vehicle registration from my API. I have output the response and found that the response is correct, but when I try to get the information it seems the vehicle registration list I have created is 0 (as shown in the screenshot below).

I am assuming my formatting is incorrect, but am hoping for some assistance here.

I ahve been getting a whole bunch of similar information in other screens from these endpoints, and fonud this block structure worked perfectly, but this time it didn’t wrk and I am stumped. Sorry about the dumb question, I am still a Thunkable beginner. I fonud the length of the object list is 0, but the response is correct, so I am not sure what I am doing wrong.

Here are mu blocks

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/9/d95c51d6c2b0224c7322e8d6f85f706c6efd0933.png)

Here is a swagger screenshot of what the format looks like.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/d/ed64153c9763c648b50026d7e47a729b01d69d8d.png)

Here are my screenshots of the two stages at the screen.

 ![336155082_173859462243894_1047913106072263831_n](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/a/4aa726bfbf4faf2352450aecb4a46b51560b672f.jpeg)  
 ![335390196_764048681749914_2523670375064779949_n](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/c/3c903312556faca722f8c6136f0f24fddad0aec3.jpeg)

---

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [March 13, 2023, 1:44am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/2 "2023-03-13T01:44:18Z")

</div>

Here is my JSON output from Postman. I think the issue is the vehicle rego detials are nested twice and I am unsure of how to go about extracting the info correctly. Any suggestions are greatly appreciated. Cheers

```auto
{
    "user_details": {
        "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
        "name": "Luke",
        "mobileNumber": "+61413555236",
        "email": "luke5@gmail.com"
    },
    "vehicle_reg": {
        "123456": {
            "model": "234566",
            "colour": "098765",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "123456",
            "make": "123456"
        },
        "123ABC": {
            "model": "Vroom vroom",
            "colour": "Pink",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "123ABC",
            "make": "Toyota"
        },
        "AAAAA": {
            "model": "Vroom vroom",
            "colour": "Pink",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "AAAAA",
            "make": "Toyota"
        },
        "ABN456": {
            "model": "hiace",
            "colour": "red",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "ABN456",
            "make": "toyota"
        },
        "TESTLPPP": {
            "model": "hiaceyyyy",
            "colour": "aquamarine",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "TESTLPPP",
            "make": "toyoto"
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2023, 2:40am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/3 "2023-03-13T02:40:40Z")

</div>

In your swagger screenshot, vehicle\_reg is an array/list but in your Thunkable screenshot, it’s not. So you can’t loop through vehicle\_reg as you’re doing in your blocks.

I think you have to do something like get the properties of the vehicle\_reg object and then loop through that list of properties.

---

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [March 13, 2023, 4:49am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/4 "2023-03-13T04:49:45Z")

</div>

I kinda get what you’re saying, but I am not sure how to implement that. Also just wanted to say thanks, I’ve noticed you are jumping on a few of my forum posts and I definitely appreciate it!

I have managed to extract the data when I know exactly what it is. See the below screenshot.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/7/37d1722aa857ab216797de5ecfbc4e12834a3f67.png)

But what I don’t get how to implement is how to extract it without knowing what the value (rego 123ABC as an example) is. From what you’ve said, I believe I have done this, but when I attempt to extract it, I get a length of 0 for the vehicle\_reg\_list and am unsure of why I am gettnig the vehicle reg info incorrectly.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/0/a04642e7bb9376d9b3b6b3cc0b051a2201c1c745.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2023, 4:58am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/5 "2023-03-13T04:58:52Z")

</div>

You’re welcome! Happy to help when I can…

Here’s how I would extract the “lpn” property:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/5/c5575b40c26b5baa196fe9c6c983a8d83156407c.png)

And the preview:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/3/a35452a39f09b03205eee262420a28fccbc7c775.png)

FYI, you can simplify the property names to “vehicle\_reg.” + j + “.lpn”. I just made them that way because the screenshot is a little easier to understand.

---

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [March 13, 2023, 5:09am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/6 "2023-03-13T05:09:06Z")

</div>

Thanks for doing up that example, but I am a bit confused by it and hoping for some clarification.

I truthfully don’t understand quite a few things you’ve done, but ended up doing this and was able to output them to the listviewer and actually populate it. It was simply adding the “get object prooperties” bit before the other section I already had. Just trying to now figure out the bit about extracting the lpn and make info for each vehicle.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/e/9e3f28e4a6b4ffb2c1b74dbc2090c8ed4ecbc624.png)

Can you explain what the JSON response is? As I am not sure exactly what that is and where it came from. I know you’ve set it at teh top, but that user information will be different for every user, so I am not sure if that would work in this case?

---

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [March 13, 2023, 5:17am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/7 "2023-03-13T05:17:56Z")

</div>

I have attempted this but it doesn’t seem to extract the correct information, just wondering if you knew what was going wrong with this setup. I tried doing it with your example, but I got fairly confused and wanted to try it a different way.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/2/d291eab383b86a033775a7a29accd5f67f0a34ab.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2023, 5:41am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/8 "2023-03-13T05:41:36Z")

</div>

Sorry, I meant to explain that the JSON response is just a static value for the JSON you posted above. Instead of calling the server, I just used your response. It has the same effect so it’s useful for testing the blocks, especially for APIs where I wouldn’t have a key to access them.

But you’re right, the JSON is going to be dynamic (different every time). If the _format_ of the JSON is the same but the values changes, then you’re fine using the blocks I provided. You just wouldn’t need the static JSON text. You’d replace that with the actual JSON response (green [response] block).

If the format changes, then you are in for quite a ride… and I’d need to see some examples of what that looks like in order to advise you.

The main problem with your blocks is that you are assuming that the “vehicle\_reg” property you’re getting from your API is an array/list. It isn’t. Square brackets in JSON [] represent an array. Curvy brackets { } represent objects.

A **list** of objects would look like this:

```auto
"vehicle_reg": [
        "123456": {
            "model": "234566",
            "colour": "098765",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "123456",
            "make": "123456"
        },
        "123ABC": {
            "model": "Vroom vroom",
            "colour": "Pink",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "123ABC",
            "make": "Toyota"
        }
]

```

But what you’re seeing is an **object** with objects inside:

```auto
"vehicle_reg": {
        "123456": {
            "model": "234566",
            "colour": "098765",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "123456",
            "make": "123456"
        },
        "123ABC": {
            "model": "Vroom vroom",
            "colour": "Pink",
            "cognito_id": "5820d31f-8d80-41c2-8372-f5aade306d20",
            "lpn": "123ABC",
            "make": "Toyota"
        }
}

```

So you’re stuck using “get property of object” blocks. What I did to make the blocks access multiple nested properties/objects is to use the “get object properties of” block. That’s a special block that is used to get the property names from inside of an object. I assign that to the loop variable **j** and then use **j** in place of the actual property name such as “123ABC” or “AAAA”.

I’m sure that’s still a little confusing but I’m not sure how else to explain it!

---

<div class="post-metadata">

**Author:** ![ankitoriginal](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ankitoriginal](https://community.thunkable.com/u/ankitoriginal)\
**Post date:** [March 13, 2023, 5:50am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/9 "2023-03-13T05:50:23Z")

</div>

Ah, I get what you mean. That makes a lot of sense, I believe I have implemented it correctly (and yes the format stays the same, but the values change). But I am not getting the correct output, pelase see the screenshos below. When I try to get the lpn values and output them to the listviewer, it doesn’t work.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/f/dfeb0d5b2a08f1c8b73a1c951a3b51ca72d61a54.png)

 ![336162027_1309917286534498_1304447766734867995_n](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/8/f8dedca04adb9541f54072a1910223f5f8a2f72e.jpeg)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2023, 6:08am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/10 "2023-03-13T06:08:08Z")

</div>

Because the API response is in JSON format, wherever you have a green [response] block, you need a “get object from JSON” block before it. You’re missing that here:

 ![Screenshot 2023-03-12 at 11.07.15 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/7/27f11b763ee459cf0a6e66735777aec862f1d026.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2023, 6:09am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/11 "2023-03-13T06:09:52Z")

</div>

Also, “j” is not an object. Using my blocks, you’re now getting a list of text strings stored in `app variable vehicle_reg_list`. So you can’t use that as an object when trying to get the “make” property.

Instead, copy the [in list…] set of blocks you’re using to get the “lpn” property and just change “lpn” to “make” here:

 ![Screenshot 2023-03-12 at 11.07.15 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/b/9bb9c697b13478c91f7f64cb44479caa47a7af26.png)

### The structure of those blocks will work for any nested property such as “model”, “colour”, etc.

The idea is that as “j” loops through the values in the list, it joins together the values to create strings like this in the `get property of object` block inside your loop:

“vehicle\_reg. **123456**.lpn”  
“vehicle\_reg. **123ABC**.lpn”  
“vehicle\_reg. **AAAAA**.lpn”

To get the “make” properties, you’d want to do the same but replace “lpn” with “make”:

“vehicle\_reg. **123456**.make”  
“vehicle\_reg. **123ABC**.make”  
“vehicle\_reg. **AAAAA**.make”

\*The values in **bold** above are your “j” values in the loop.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2023, 6:16am UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/12 "2023-03-13T06:16:37Z")

</div>

I gotta get some sleep but hopefully that will get you far enough along to retrieve some of the values you need…

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 1:36pm UTC](https://community.thunkable.com/t/getting-the-correct-object-array-from-an-api-json-input/2320685/13 "2024-11-08T13:36:57Z")

</div>


