> For the complete documentation index, see [llms.txt](https://modelico.javiercejudo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://modelico.javiercejudo.com/quickstart/nested_types_example.md).

# 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))
    })
  }
}
```
