# Nested types example

The [introductory example](/quickstart.md) features a standalone class. Let's look at a more involved example that builds on top of that:

```javascript
{
  "givenName": "Javier",
  "familyName": "Cejudo",
  "pets": [
    {
      "name": "Robbie"
    }
  ]
}
```

Notice that the data contains a list of pets (`Animal`).

Again, our goal is to parse JSON into JavaScript classes to be able to do things like

```javascript
const person1 = M.fromJSON(Person, personJson)

person1.fullName() // => 'Javier Cejudo'
person1.pets().get(0).speak() // => 'my name is Robbie!'
```

*Note: pets() returns a `Modelico.List`, which has a `get` method, but little more. To `map`, `filter` or perform other operations, you will need to grab the underlying array with `.inner()`. See the* [*proxies docs*](/advanced/proxies.md) *for a way to use methods and properties of the inner structure directly.*

To achieve our goal, we need a `Person` that references `Animal` within its inner types using the `M.metadata()._` function.

```javascript
import M from 'modelico'

const {_, string, list} = M.metadata()

class Person extends M.Base {
  fullName () {
    return `${this.givenName()} ${this.familyName()}`.trim()
  }

  static innerTypes () {
    return Object.freeze({
      givenName: string(),
      familyName: string(),
      pets: list(_(Animal))
    })
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://modelico.javiercejudo.com/quickstart/nested_types_example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
