> For the complete documentation index, see [llms.txt](https://docs.atfinity.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.atfinity.io/rule-language/operators/dictionary-operators/to_dict.md).

# to\_dict

{% hint style="info" %}
**New in Atfinity 17.**
{% endhint %}

### Description

`to_dict` builds a dictionary from selected attributes of an [instance](/guides/glossary/instance.md). The argument is a dictionary literal whose keys are the attribute names to read from the instance.

For each entry:

* If only an attribute name is given (using the [dictionary shorthand](/rule-language/operators/dictionary-operators/shorthand.md), e.g. `first_name`), the resulting dictionary uses the attribute name itself as the key.
* If a value is given (e.g. `first_name: 'givenName'`), that value is used as the key in the resulting dictionary.

Attributes whose value is `unknown` (i.e. not set on the instance) are skipped and do not appear in the resulting dictionary.

### Examples

```
p is Person
p.to_dict({first_name, last_name})
// => {'first_name': 'Thorben', 'last_name': 'Croisé'}
```

Renaming all keys:

```
p is Person
p.to_dict({first_name: 'givenName', last_name: 'familyName'})
// => {'givenName': 'Thorben', 'familyName': 'Croisé'}
```

Mixing shorthand and explicit renames:

```
p is Person
p.to_dict({first_name, last_name: 'familyName'})
// => {'first_name': 'Thorben', 'familyName': 'Croisé'}
```

To narrow down or rename keys of an existing dictionary (rather than building one from an instance), use [`pick`](/rule-language/operators/dictionary-operators/pick.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.atfinity.io/rule-language/operators/dictionary-operators/to_dict.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.
