---
schema_version: "1"
id: 4266577abcc5fc58a9fc2e5b2c1091b489d27d8c46678625d418bff2cabaab9b
title: Data Serialization Functions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_bindings/guides/bi-dashboard-bindings-functions-wave-designer-data-serialization.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-functions-wave-designer-data-serialization.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: fd41fe1ca82bbf2e3fc6913d28e97f2185087d6bc9a51f4ca391ae3d3869076d
products:
  - Analytics Interactions
  - analytics
---
<!-- Contains overview of serialization functions, asDateRange Function, asEquality Function, asGrouping Function, asObject Function, asOrder Function, asProjection Function, asRange Function and asString Function -->

# Data Serialization Functions

Serialization functions convert the data into the form expected by the query in which the interaction is inserted. For example, if the interaction is used in a compact-form query, use the `asObject` function to format the data into a one-dimensional object.

## asDateRange Function

Returns the date range filter condition as a string for a SAQL query. The date range is inclusive. Use the string as part of a filter based on dates.

The input data must be a one- or two-dimensional array. If the input data is a one-dimensional array with two elements, the function uses the first element as the minimum and the second element as the maximum. Null results in `fieldName in all`, which applies no filter.

To view an example of this function, see [Date Range Filter Interaction](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-filter-interactions.md#date-range-filter-interaction).

### Syntax

```javascript
<input data>.asDateRange(fieldName)
```

### Arguments

| Argument  | Description                            |
| --------- | -------------------------------------- |
| fieldName | (Required) The name of the date field. |

This example is based on the `stepFoo` source query. Assume that `stepFoo.selection` retrieves this row from the query.

```json
[{ "min": 1016504910000, "max": 1281655993000 }]
```

### Example

Function:

```javascript
row(stepFoo.selection, [0], ["min", "max"]).asDateRange("date(year, month, day)");
```

Output:

```sql
date(year, month, day) in [dateRange([2002,3,19], [2010,8,12])]
```

See Also

- [Date Range Filters](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-use-case-filter-date-range.md)

## asEquality Function

Returns an equality or "in" filter condition as a string for a SAQL query. The input data must be a scalar, one-dimensional array, or a two-dimensional array.

If a single field name is provided, the returned string contains the `in` operator for a one-dimensional array, `fieldName in ["foo", "bar"]`, or the equality operator for a scalar, `fieldName == "foo"`.

If multiple field names are provided, the returned string contains a composite filter. For this case, a two-dimensional array is expected. The number of values in each array must match the number of specified fields.

**note:** If the input to this function is `null`, the function returns `<fieldName> is null`, where `<fieldName>` is the first field. For example, if `cell(step1.selection, 0, "column1")` evaluates to `null`, `cell(step1.selection, 0, "column1").asEquality("field1")` evaluates to `'field1' is null`. If there are no selected rows, `cell(step1.selection, "column1")`, the function evaluates to `<fieldName> in all`.

### Syntax

```javascript
<input data>.asEquality(fieldName)
```

### Arguments

| Argument  | Description                       |
| --------- | --------------------------------- |
| fieldName | (Required) The name of the field. |

These examples are based on the `myStep` source query. Assume that `myStep.selection` is:

```json
[
    {grouping: "first", measure: 19}
    {grouping: "second", measure: 32}
]
```

### Examples

Function:

```javascript
cell(myStep.selection, 1, "measure").asEquality("bar");
```

Output:

```sql
bar == 32
```

---

Function:

```javascript
column(myStep.selection, ["grouping"]).asEquality("bar");
```

Output:

```sql
bar in ['first','second']
```

---

This example illustrates how a lack of input data is handled. Imagine that `myStep.selection` resolves as

```nolang
[]
```

Function:

```javascript
cell(myStep.selection, 0, "value").asEquality("bar");
```

Output:

```sql
'bar' in all
```

---

The next examples illustrate how null values and empty arrays are evaluated when present in the `myStep.selection`.

```json
[
  { "grouping": "first", "measure": null },
  { "grouping": "second", "measure": 32 }
]
```

Function:

```javascript
cell(myStep.selection, 0, "measure").asEquality("bar");
```

Output:

```sql
'bar' is null
```

```sql
[
    {label: "Bananas", value: []}
]
```

Function:

```javascript
cell(myStep.selection, 0, "value").asEquality("bar");
```

Output

```sql
'bar' in all
```

See Also

- [Filters](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-use-case-filter-equality.md)

## asGrouping Function

Returns a grouping as a string. Can also return multiple groupings

The input data must be a scalar or one-dimensional array of groupings. Null results in a `group by all`.

To view an example of this function, see [Group and Project Interaction](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-filter-interactions.md#group-and-projection-interaction).

### Syntax

```javascript
<input data>.asGrouping()
```

Let's look at some examples where the selection determines the groupings in a SAQL-form query. These examples are based on the `stepFoo` source query. Assume that `stepFoo.selection` retrieves these rows from the query.

```json
[
    {grouping: "first", alias: "foo"}
    {grouping: "second", alias: "bar"}
]
```

### Examples

Function:

```javascript
cell(stepFoo.selection, 1, "grouping").asGrouping();
```

Output:

```sql
'second'
```

---

Function:

To make the interaction return multiple fields for the grouping, replace the `cell` interaction function with a `column` function and update the arguments.

```javascript
column(stepFoo.selection, ["grouping"]).asGrouping();
```

Output:

```sql
('first', 'second')
```

See Also

- [Group Interactions](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-use-case-group.md)

## asObject Function

Passes data through with no serialization. Returns data as an object that is an array of strings.

### Syntax

```javascript
<input data>.asObject()
```

### Examples

Function:

```javascript
column(StaticMeasureNamesStep.selection, [\"value\"]).asObject()
```

---

Function:

```javascript
cell(static_1.selection, 0, \"value\").asObject()
```

See Also

- [Bind Parts of a Query](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-use-case-query-parts.md)

## asProjection Function

Returns the query expression and alias as a string that you can use to project a field in a query. The query expression determines the value of the field. The alias is the field label.

Use this function to write a `foreach` statement for a field projection. The function concatenates the query expression `as` and the field label in this format.

```nolang
<`query_expression`> as <`field_label`>
```

Here's a sample projection that rounds the price to two decimals and stores the result in the `SalesPrice` field.

```javascript
q = foreach q generate round(Price, 2) as SalesPrice;
```

In this sample, `round(Price, 2)` is the expression and `SalesPrice` is the field label.

### Syntax

```javascript
<input data>.asProjection()
```

This example is based on the `stepFoo` source query. Assume that `stepFoo.selection` retrieves these rows from the query.

```json
[
    {expression: "first", alias: "foo"}
    {expression: "second", alias: "bar"}
]
```

### Examples

Function:

```javascript
stepFoo.selection, [0], ["expression", "alias"]).asProjection()
```

Output:

```sql
first as 'foo'
```

---

Function:

```javascript
stepFoo.selection, [], ["expression", "alias"]).asProjection()
```

Output:

```sql
first as 'foo', second as 'bar'
```

See Also

- [Projection Interactions](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-use-case-projection.md)

## asRange Function

Returns a range filter condition as a string for a SAQL query. The range is inclusive.

The input data must be a one-dimensional array with at least two elements. The function uses the first as the minimum and the second as the maximum. Null results in `fieldName in all`, which applies no filter.

To view an example of this function, see [Range Filter Interaction](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-filter-interactions.md#range-filter-interaction).

### Syntax

```javascript
<input data>.asRange(fieldName)
```

### Arguments

| Argument  | Description                       |
| --------- | --------------------------------- |
| fieldName | (Required) The name of the field. |

This example is based on the `myStep` source query. Assume that `myStep.selection` retrieves these rows from the query.

```json
[
    {grouping: "first", measure: 19}
    {grouping: "second", measure: 32}
]
```

### Example

Function:

```javascript
row(myStep.selection, [0], ["min", "max"]).asRange("bar");
```

Output:

```sql
bar >= 19 && bar <= 32
```

See Also

- [Range Filters](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-use-case-filter-range.md)

## asString Function

Serializes a scalar, one-dimensional array, or a two-dimensional array as a string. Escapes double quotes in strings.

### Syntax

```javascript
<input data>.asString()
```

### Examples

Function:

```javascript
cell(stepOpportunity.selection, 1, "measure").asString();
```

---

Function:

```javascript
cell(color_1.result, 0, "color").asString();
```

See Also

- [Highlight Values with Color Coding](https://developer.salesforce.com/docs/analytics/bi-dev-guide-bindings/guide/bi-dashboard-bindings-wave-designer-color-code-values.md)
