# Custom Data Types

Custom Data Types are objects. Each application can have access to arbitrarily many Custom Data Types, which are accessed and edited in the [AirData Builder](../studio/studio/builder-bar/airdata-builder). Each Custom Data Type consists of any number of properties, structured into key-value pairs. The expected Data Type of each property is also defined in the AirData Builder. A property can expect any primitive Data Type as well as other Custom Data Types.

In concept and in practice, Custom Data Types are similar to [AirData App Objects](../working-with-data/working-with-data-overview/airdata/airdata-app-objects). The fundamental difference is that AirData App Objects define a way to structure data that can be saved to [AirData](../working-with-data/working-with-data-overview/airdata), whereas Custom Types can only be used to define local variables for reference within the context of a Journey.

## Structure

Custom Data Types must be objects, consisting of any number of key-value pairs. Beyond that, their structure is, as the name implies, highly customizable. Structuring the Custom Data Type is a part of the creation process.

There are two ways to create a new Custom Data Type:

1. Create a new Custom Type and manually define all of it's properties in [AirData Builder](../studio/studio/builder-bar/airdata-builder).
2. Save the structure of data returned by a Data Operation from [Connections Builder](../studio/studio/builder-bar/connections-builder).

## Examples

### Structuring Custom Data Types in AirData Builder

Custom Data Types are created in the AirData Builder by clicking on the '+' icon to the right of the **Custom Types** branch in the Tree:

![organizing info](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-312db75d93922ae6a9216a376152d61f46719e4e%2Fcustom-data-types-v184-0.png?alt=media)

Upon creation, it is best practice to rename the Custom Data Type so that it is self-documenting. Do this by double-clicking directly on the Custom Data Type within the Tree and typing a more descriptive name:

![organizing info](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-29a9994f8683ebffde539c3c9feb5afaa1cbff74%2Fcustom-data-types-v184-1.png?alt=media)

Add any number of properties to the Custom Data Type by clicking the '+' icon to the right of the relevant Custom Data Type, which provides the option to select the Data Type of the property:

![organizing info](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-2e723d8a9a7f47eaf950e4e7d25b597717950137%2Fcustom-data-types-v184-2.png?alt=media)

Properties names are edited in the same way as the Custom Data Types names.

As properties are added to a Custom Data Type, the Stage displays an example how the Custom Data Type might appear in Airscript. Note how properties within the [DateTime](the-datetime-variable-data-type) property, `datetime_property`, are nested:

![organizing info](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-62c19f352c1d3f2cbb050106790cec74874700db%2Fcustom-data-types-v184-3.png?alt=media)

### Saving the Structure of Incoming Data from Connections Builder

Several Data Operations return output that might potentially be structured as an object. In such cases, the bottom left of the Data Operation as displayed the Stage of the Connections Builder will contain the following button:

![organizing info](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-d3ac3b8b9f674e27be690e6f31d4fd224bfbaba6%2Fcustom-data-types-v184-4.png?alt=media)

Clicking on this button saves the structure of the Data Operation's current returned value as a new Custom Type. For example, say the [HTTP Request](../data-operations/data-operation-overview/http-request-data-operation) Data Operation is run, returning the following JSON object:

![organizing info](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-1c99eb8240fb8635fcef10c44e9732795c9f6a92%2Fcustom-data-types-v184-5.png?alt=media)

Upon clicking the **Save Type** button, the following Custom Data Type will be automatically generated in AirData Builder:

![](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-760d866916d9edfd49b2032e1a77965e38c47255%2Fcustom-data-types-v184-6.png?alt=media)

Note that the properties associated with this automatically-generated Custom Data Type correspond to the properties of the JSON object returned by the earlier HTTP Request.

The names of Custom Data Types generated in this way can be edited in the same was as any other Custom Data Type: double-clicking directly on the Custom Data Type within the Tree and typing a new name.

### Using Custom Data Types

Once the structure of a Custom Data Type has been finalized, it can be used to define variables just like any other Data Type.

Reference properties within a Custom Data Type using dot notation. For instance, assuming the a variable of the Auto-Generated Type described in the above screenshot is designated `autogenerated_type` and contains the following value:

```javascript
{
  "activity": "Draw something interesting",
  "type": "recreational",
  "participants": 1,
  "price": 0,
  "link": "",
  "key": "8033599",
  "accessibility": 0
}
```

The `activity` property would be referenced as follows:

```javascript
autogenerated_type.activity -> "Draw something interesting"
```

Similarly, the `participants` property is referenced as follows:

```javascript
autogenerated_type.participants -> 1
```
