Maps

Maps are special data types which represent name-value pairs which can be set and retrieved using the special map-related blocks. Maps are an efficient way to create a list of items that can be searched quickly.  

Examples

A common use for maps is to define relationships between one piece of data and another. This is often called a map of "key/value pairs". For instance, the following map can be used to translate an airport code to its associated city. The key ATL will retrieve the value "Atlanta":



Maps can also be used as a sort of "anonymous object" useful for deserializing JSON of an unknown structure, instead of formally defining a type.


To learn more about a map, a best practice is to deserialize it into text, and place that text into a multiline text field so it can be viewed while the configurator is running:

S


Maps have text as their key, but can have any datatype as their value... including other maps.  In this way, you can drill down through a complex tree of unknown length and depth by simply looking up a key to get the value (a map), and then use that returned map as the source of a second lookup of a key to get a third map... and so on.  Often, data integrated from other systems is transmitted in a map stored as JSON.  See this example of parsing a complex JSON tree of data from another source.


Maps are also very useful for cases where you have a large in-memory array of many different elements, and you need to find a specific element.  Elements of an array can be retrieved quickly by their ID (their position in the array), but trying to retrieve by any other attribute can be slow.  Solve the problem by creating a map to help you find the ID of any member in the array.  Then simply use the map to get the ID you need.  See the how-to document on Complex Types for more information and example code.





Was this article helpful?