---
title: 'Nested object'
---

# Nested object

While kysely is not an ORM and it doesn't have the concept of relations, we do provide
helpers for fetching nested objects and arrays in a single query. In this example we
use the `jsonObjectFrom` helper to fetch person's favorite pet along with the person's id.

Please keep in mind that the helpers under the `kysely/helpers` folder, including
`jsonObjectFrom`, are not guaranteed to work with third-party dialects. In order for
them to work, the dialect must automatically parse the `json` data type into
JavaScript JSON values like objects and arrays. Some dialects might simply return
the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
to parse the results.

import {
  Playground,
  exampleSetup,
} from '../../../src/components/Playground'

import {
  nestedObject
} from './0120-nested-object'

<div style={{ marginBottom: '1em' }}>
  <Playground code={nestedObject} setupCode={exampleSetup} />
</div>

:::info[More examples]
The API documentation is packed with examples. The API docs are hosted [here](https://kysely-org.github.io/kysely-apidoc/),
but you can access the same documentation by hovering over functions/methods/classes in your IDE. The examples are always
just one hover away!

For example, check out these sections:
 - [select method](https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#select)
 - [selectAll method](https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#selectAll)
 - [selectFrom method](https://kysely-org.github.io/kysely-apidoc/classes/Kysely.html#selectFrom)
:::
