Edit

Share via


bag_zip()

Applies to: ✅ Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

Creates a dynamic property-bag from two input dynamic arrays. In the resulting property-bag, the values from the first input array are used as the property keys, while the values from the second input array are used as corresponding property values.

Syntax

bag_zip(KeysArray, ValuesArray)

Learn more about syntax conventions.

Parameters

Name Type Required Description
KeysArray dynamic ✔️ An array of strings. These strings represent the property names for the resulting property-bag.
ValuesArray dynamic ✔️ An array whose values will be the property values for the resulting property-bag.

Note

  • If there are more keys than values, missing values are filled with null.
  • If there are more values than keys, values with no matching keys are ignored.
  • Keys that aren't strings are ignored.

Returns

Returns a dynamic property-bag.

Examples

In the following example, the array of keys and the array of values are the same length and are zipped together into a dynamic property bag.

let Data = datatable(KeysArray: dynamic, ValuesArray: dynamic) [
    dynamic(['a', 'b', 'c']), dynamic([1, '2', 3.4])
];
Data
| extend NewBag = bag_zip(KeysArray, ValuesArray)
KeysArray ValuesArray NewBag
['a','b','c'] [1,'2',3.4] {'a': 1,'b': '2','c': 3.4}

More keys than values

In the following example, the array of keys is longer than the array of values. The missing values are filled with nulls.

let Data = datatable(KeysArray: dynamic, ValuesArray: dynamic) [
    dynamic(['a', 'b', 'c']), dynamic([1, '2'])
];
Data
| extend NewBag = bag_zip(KeysArray, ValuesArray)
KeysArray ValuesArray NewBag
['a','b','c'] [1,'2'] {'a': 1,'b': '2','c': null}

More values than keys

In the following example, the array of values is longer than the array of keys. Values with no matching keys are ignored.

let Data = datatable(KeysArray: dynamic, ValuesArray: dynamic) [
    dynamic(['a', 'b']), dynamic([1, '2', 2.5])
];
Data
| extend NewBag = bag_zip(KeysArray, ValuesArray)
KeysArray ValuesArray NewBag
['a','b'] [1,'2',2.5] {'a': 1,'b': '2'}

Non-string keys

In the following example, there are some values in they keys array that aren't of type string. The non-string values are ignored.

let Data = datatable(KeysArray: dynamic, ValuesArray: dynamic) [
    dynamic(['a', 8, 'b']), dynamic([1, '2', 2.5])
];
Data
| extend NewBag = bag_zip(KeysArray, ValuesArray)
KeysArray ValuesArray NewBag
['a',8,'b'] [1,'2',2.5] {'a': 1,'b': 2.5}

Fill values with null

In the following example, the parameter that is supposed to be an array of values isn't an array, so all values are filled with nulls.

let Data = datatable(KeysArray: dynamic, ValuesArray: dynamic) [
    dynamic(['a', 8, 'b']), dynamic(1)
];
Data
| extend NewBag = bag_zip(KeysArray, ValuesArray)
KeysArray ValuesArray NewBag
['a',8,'b'] 1 {'a': null,'b': null}

Null property-bag

In the following example, the parameter that is supposed to be an array of keys isn't an array, so the resulting property-bag is null.

let Data = datatable(KeysArray: dynamic, ValuesArray: dynamic) [
    dynamic('a'), dynamic([1, '2', 2.5])
];
Data
| extend NewBag = bag_zip(KeysArray, ValuesArray)
| extend IsNewBagEmpty=isnull(NewBag)
KeysArray ValuesArray NewBag IsNewBagEmpty
a [1,'2',2.5] TRUE