Day #6 with Cloud Workflows: arrays and dictionaries

So far, in this series of articles on Cloud Workflows, we have used simple data types, like strings, numbers and boolean values. However, it’s possible to use more complex data structures, like arrays and dictionaries. In this new episode, we’re going to use those new structures.

Arrays can be defined inline (like anArray ) or spanning over several lines (like anotherArray ):

- assignment:
assign:
- anArray: ["a", "b", "c"]
- anotherArray:
- one
- two
- output:
return: ${anArray[0] + anotherArray[1]}

For dictionaries, you can define them as follows:

- assignment:
assign:
- person:
firstname: "Guillaume"
lastname: "Laforge"
age: 43
kids: ["Marion", "Erine"]
- output:
return: ${person.firstname + " and " + person.kids[1]}

The output step will return the string “Guillaume and Erine”.

Notice that we nested an array within a dictionary. So you can easily create dictionaries containing arrays, containing other dictionaries, etc, just like any JSON or YAML structures.

In the example we were able to access the second kid of the person, mixing both the field (dot) and index (square brackets) notations to access fields of our dictionary, and elements of our array.

This video shows both arrays and dictionaries in action:

In the coming articles, we’ll see that such data structures are handy for dealing with API endpoint calls.

Originally published at http://glaforge.appspot.com.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Guillaume Laforge

Guillaume Laforge

2.7K Followers

Developer Advocate for Google Cloud Platform, Apache Groovy programming language project VP/Chair