Using the MAP function to select a set of values in the second array of a JSON file type

This article shows you how to select a field and its associated value in the second array of a JSON file type.

In this use case, you find you are able to select a field and value in the first array ({}) of the data source file but you are unable to select a field and value in the second array ({})({}) of the data source file.

The MAP function is an advanced function. For more information about this function, see MAP function.


In this set of instructions, you will:

  • Build a Table component
  • Use the MAP function
  • Use the DATASOURCE function

This Klip uses the following data source:

Step 1: Building a column in the Table component

Goal: Use the MAP function to return a set of values from the second array of a JSON file type.

  1. Select Build a New Klip.
  2. Select the Table component.
  3. Select Use an existing data source from the library and select your data source.
  4. From the component tree, select Klip, and type a Klip Title.

Location

Action

Result

From the component tree select Column: Unnamed 1.  
From the formula editing toolbar

Select Insert function, Data Manipulation, MAP.
The MAP function assigns a name to a list of elements and then applies a function to each element in the list.

MAP( values , variable name , expression )
With values selected.

Select Insert function, ARRAY.
The ARRAY function joins together a list of single values.

MAP( ARRAY( data ) , variable name , expression )
With data selected Select the Insert literal string or number button and type in the field name from the data source file that you want to return, and click the Apply button. MAP( ARRAY( 15 ) , variable name , expression )
With data selected

Repeat for other fields in the data source file you want to return. Tip: Click ARRAY to see the next data parameter. 

MAP( ARRAY( 15 , 1217 , data) , variable name , expression )
With variable name selected

Select the Insert literal string or number button and type in a name for this variable, and click the Apply button.

MAP( ARRAY( 15 , 1217  , data) , "temp" , expression )

Select the Insert Variable button and create a new variable for this name.


With expression selected

Select Insert function, Data Manipulation, DATASOURCE.
The DATASOURCE function dynamically resolves a data pointer to a data source file.

MAP( ARRAY( 15 , 1217 , data) , "temp" , DATASOURCE( datasource id , pointer )
With the data source id selected

Select the Insert literal string or number button and paste in the data source id and click the Apply button. For more information on locating the data source id, see DATASOURCE function.

MAP( ARRAY( 15 , 1217 , data) , "temp" ,DATASOURCE( b81121b321f16bd304c6855cdbce1030 , pointer)
With pointer selected

Select Insert function, Text, CONCAT.
The CONCAT function joins two or more values into one text string.


MAP( ARRAY( 15 , 1217 , data) , "temp" , DATASOURCE( b81121b321f16bd304c6855cdbce1030 , CONCAT( data ) ) )
With data selected.

Select the Insert literal string or number button and type in

/alerts[@name=

and click the Apply button.

MAP( ARRAY( 15 , 1217 , data) , "temp" , DATASOURCE( b81121b321f16bd304c6855cdbce1030 , CONCAT( /alerts[@name= ) ) )
With data selected.

Select the Insert variable button and select your variable name, e.g. temp

MAP( ARRAY( 15 , 1217 , data) , "temp" ,DATASOURCE( b81121b321f16bd304c6855cdbce1030 , CONCAT( "/alerts[@name=" , temp , data ) ) )
With data selected.

Select the Insert literal string or number button and type in ] and click the Apply button.

MAP( ARRAY( 15 , 1217 , data) , "temp" ,DATASOURCE( b81121b321f16bd304c6855cdbce1030 , CONCAT( "/alerts[@name=" , temp , "]" ) ) )
With the formula selected.

Select the Evaluate current selection button.

Result: 0, 1

Feedback and Knowledge Base