Skip to main content

Data access in JSON projects

All examples on this page use the JSON data in this downloadable file. The topic is easier to follow if you create a "Describe a JSON Object" project and upload the cakes.json data file.

When you upload JSON data, Studio creates a special variable called WholeJSON, which gives you access to the complete dataset. You can then access the fields of the data in two ways:

  1. Bracket notation

  2. Dot notation

Tip

You must use bracket notation to access elements within a JSON array. See the examples below.

These examples use the cakes.json data file mentioned above.

ATL in Script

Result

Notes

[[WholeJSON['name']]]

Karen's Cake Shop

Uses bracket notation to retrieve the value of the "name" field.

[[WholeJSON.name]]

Karen's Cake Shop

Uses dot notation to retrieve the value of the "name" field.

[[WholeJSON['customers'][2]['name']]]

Richard Gordon

Uses bracket notation to access the third element in the "customers" array and then retrieve the value of the "name" field. Note that zero-based indexing applies.

[[WholeJSON.customers[2].name]]

Richard Gordon

Retrieves the same value as above but uses a mixture of dot notation and bracket notation. Note that you must use bracket notation to access elements within an array.

[[WholeJSON['customers'][2]['items'][0]['name']]]

Chocolate Cake

Uses bracket notation to access the third element in the "customers" array and then the "items" array within that element. Finally, it accesses the first element within "items" and retrieves the value of the "name" field.

[[WholeJSON.customers[2].items[0].name]]

Chocolate Cake

Retrieves the same value as above but uses a mixture of dot notation and bracket notation. Note that you must use bracket notation to access elements within an array.

Tip

Field/key names should not contain dots or begin with a dollar symbol ($). If the name contains a non-alphanumeric character (e.g. an underscore) or begins with a numeral, you must use bracket notation to access the field/key.

If your project requires repeat access to the same parts of your JSON structure, you can save time and simplify your ATL scripts by creating user-defined variables (of JSON type) that serve as shortcuts to those parts. For example:

Variable Name

Variable Type

Data Source

ATL in Script

Result

cust

JSON

[[WholeJSON.customers]]

[[cust[2].items[0].name]]

Chocolate Cake

The ATL [[WholeJSON.customers]] has been turned into a user-defined variable named cust. Once defined, this variable can be used in another piece of ATL. Notice that [[cust[2].items[0].name]] returns the same result as [[WholeJSON.customers[2].items[0].name]].

Tip

Studio has many functions for manipulating your data. Most of the functions applicable to JSON data are in the Advanced functions section; however, some data access functions also work on JSON data.