# JSON Parsing - Accessing Dictionary Nested Within Auto(), Nested Within Auto()

**URL:** <https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636>\
**Category:** General\
**Created:** [May 21, 2019, 1:57pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636 "2019-05-21T13:57:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Schacht](https://forum.xojo.com/user_avatar/forum.xojo.com/aaron_schacht/32/7613_2.png) [@Aaron\_Schacht](https://forum.xojo.com/u/Aaron_Schacht)\
**Post date:** [May 21, 2019, 1:57pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/1 "2019-05-21T13:57:23Z")

</div>

I am having an issue accessing a Dictionary that’s being created when I’m getting patient information from an EMR provider (Athena). I’m having no issues iterating through patient records when I search by patient name and DOB… I get a Dictionary nested within another Dictionary and I can work with this. HOWEVER, when I do a GET by Patient ID, it returns an Auto() nested within another Auto() which contains the Dictionary.

So, can anyone tell me how I access an Auto() value within another Auto()? I believe it’s essentially an array within another array, right?

Sub PageReceived(url as string, httpStatus as integer, headers as internetHeaders, content as string)  
Dim buffer As Text = content.defineEncoding(Encodings.UTF8).convertEncoding(Encodings.UTF8).ToText  
Dim cHeaders As InternetHeaders = headers 'This isn’t really necessary…just prevents warning when compiled  
cHeaders = cHeaders 'This isn’t really necessary…just prevents warning when compiled

// Add brackets so JSON is well-formed and we parse to create a dictionary (“records”)  
buffer = “[” + buffer +"]"

Dim records() As Auto = Xojo.Data.ParseJSON(buffer) 'Gets parsed JSON data in form of Dictionary or array of Dictionaries

Dim rec As Xojo.Core.Dictionary = records(0)

---

<div class="post-metadata">

**Author:** ![Aaron\_Schacht](https://forum.xojo.com/user_avatar/forum.xojo.com/aaron_schacht/32/7613_2.png) [@Aaron\_Schacht](https://forum.xojo.com/u/Aaron_Schacht)\
**Post date:** [May 21, 2019, 2:03pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/3 "2019-05-21T14:03:45Z")

</div>

Here’s an image that might make things clearer:

![](https://i.imgur.com/5uJwaaG.png)

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [May 21, 2019, 2:34pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/4 "2019-05-21T14:34:11Z")

</div>

Something like:

```auto
Dim recs() As Xojo.Core.Dictionary = records 
Dim currentRec As Xojo.Core.Dictionary = recs(0)
```

---

<div class="post-metadata">

**Author:** ![Aaron\_Schacht](https://forum.xojo.com/user_avatar/forum.xojo.com/aaron_schacht/32/7613_2.png) [@Aaron\_Schacht](https://forum.xojo.com/u/Aaron_Schacht)\
**Post date:** [May 21, 2019, 7:42pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/5 "2019-05-21T19:42:40Z")

</div>

Derk - thank you…I’m pretty sure this is what I’m doing but I’m getting an OutofBoundsException error. The problem is that the Dictionary is nested within another Auto() . Please see my attached image.

Thanks!

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 21, 2019, 7:49pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/6 "2019-05-21T19:49:22Z")

</div>

Have you tried

```auto
dim recs() as Auto = records(0)
dim currentRecord as Xojo.Core.Dictionary = recs(0)
```

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [May 21, 2019, 8:35pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/7 "2019-05-21T20:35:11Z")

</div>

[quote=437565:@Aaron Schacht]Derk - thank you…I’m pretty sure this is what I’m doing but I’m getting an OutofBoundsException error. The problem is that the Dictionary is nested within another Auto() . Please see my attached image.

Thanks![/quote]

In your fist post you see:  
Records | Auto(0)  
That means there is 1 item of type auto in your records() As Auto array.

You should be checking if records().ubound \<\> -1  
And also keep track of the ubound in loops.

I dont see where you get the OutOfBoundsException.

If the array has other arrays in it you should be selecting the right thing, that is probably:

```auto
Dim RecordsDicts() As Xojo.Core.Dictionary = records
Dim Record As Xojo.Core.Dictionary = RecrodsDict(0)

```

But do check if the index actually exists.

---

<div class="post-metadata">

**Author:** ![Aaron\_Schacht](https://forum.xojo.com/user_avatar/forum.xojo.com/aaron_schacht/32/7613_2.png) [@Aaron\_Schacht](https://forum.xojo.com/u/Aaron_Schacht)\
**Post date:** [May 24, 2019, 1:30pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/8 "2019-05-24T13:30:50Z")

</div>

@Tim Hare This got me on the right track…thank you! Your suggestion, along with some other changes to my code got everything working.

@Derk Jochems Thank you for giving me some other ideas of how to work with Dictionaries!

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 3:56pm UTC](https://forum.xojo.com/t/json-parsing-accessing-dictionary-nested-within-auto-nested-within-auto/48636/9 "2021-04-29T15:56:55Z")

</div>


