One of the most powerful features of circuits is the ability to cherry pick specific pieces of data for analysis and logical operations.  Let's walk though an example of referring to this data in the Switch component.



The "Property" field is a bit of a mystery. How do you use it? What values can you put in there, and what is the syntax for them? The confusing answer is that it depends ... depends on the specific structure of the data coming in to it. So let's use a specific example to highlight the syntax.


Bitcoin Transactions: This component sends data that is a little bit structured, but is not incredibly complex. The data is JSON format, and looks like this:

{
  "hash": "624d5f7b21f5cef2dfacffa11d3df48bde253067daf4fe2f9e66ea248c3bf709",
  "from": [
    {
      "address": "3BU4neHNyRHAVd9CtdGHFrMLx3uT5YC4s2",
      "sats": 6901843,
      "btc": 0.06901843
    }
  ],
  "to": [
    {
      "address": "3PbEHc3gx8k5zxkNo9r322RSsAYb27A7PL",
      "sats": 1290805,
      "btc": 0.01290805
    },
    {
      "address": "bc1qd9ppvrhq3trnedls4ump62herjgqjy3uvcp26t",
      "sats": 5607542,
      "btc": 0.05607542
    }
  ],
  "totalSpent": 0.06901843
}


Within that data, there are several layers of information. At the topmost layer, there are 4 items: 

{
  "hash": xxxx,
  "from": xxx,
  "to": xxx,
  "totalSpent": xxx
}

You can refer to any of these directly in the Switch Property field and get the value for that Property. If you type "totalSpent" (without the quotes) into the Property field, you can then use it and perform operations on it, like "if totalSpent is greater than 5 btc", like this:

But what if you want to get to the deeper level items?  The "from" data looks like this:

"from": [
    {
      "address": "3BU4neHNyRHAVd9CtdGHFrMLx3uT5YC4s2",
      "sats": 6901843,
      "btc": 0.06901843
    }
  ]


Those square brackets tell us that this is an array. An array is a list of items, referenced like this: ["Ford", "BMW", "Fiat"], and we are going to need to use array-specific syntax, like this: cars[0] (assuming that array was called cars). Arrays are 0-indexed, meaning that their first element is referenced with a 0, not a 1, as in standard counting.


Here is a more in-depth explanation of arrays in JSON.


So for our example, "from", this array has only one item. Now that item is another JSON object, rather than the strings (text) in the example above.  To reference this directly, we would use from[0].


Now, to get into the items within that object, we use something called "dot notation", where we put a . and then the name of the property we want to access in there.  In this case, entering from[0].btc would return us 0.06901843 (this is the "value" stored for the key, "btc").


Here is a more in-depth explanation of objects in JSON.


Let's go through all of the possible ways to access the data that comes from the Bitcoin Transactions component and what you would get.


Value entered in "Property"
Data that will be used in the comparison
hash
624d5f7b21f5cef2dfacffa11d3df48bde253067daf4fe2f9e66ea248c3bf709
from
[
    {
      "address": "3BU4neHNyRHAVd9CtdGHFrMLx3uT5YC4s2",
      "sats": 6901843,
      "btc": 0.06901843
    }
]


from[0]
{
      "address": "3BU4neHNyRHAVd9CtdGHFrMLx3uT5YC4s2",
      "sats": 6901843,
      "btc": 0.06901843
}


from[0].address
3BU4neHNyRHAVd9CtdGHFrMLx3uT5YC4s2
from[0].sats
6901843
from[0].btc
0.06901843
to
[
    {
      "address": "3PbEHc3gx8k5zxkNo9r322RSsAYb27A7PL",
      "sats": 1290805,
      "btc": 0.01290805
    },
    {
      "address": "bc1qd9ppvrhq3trnedls4ump62herjgqjy3uvcp26t",
      "sats": 5607542,
      "btc": 0.05607542
    }
]


to[0]
  {
      "address": "3PbEHc3gx8k5zxkNo9r322RSsAYb27A7PL",
      "sats": 1290805,
      "btc": 0.01290805
  }


to[0].address
3PbEHc3gx8k5zxkNo9r322RSsAYb27A7PL
to[0].sats
1290805
to[0].btc
0.01290805
to[1]
  {
      "address": "bc1qd9ppvrhq3trnedls4ump62herjgqjy3uvcp26t",
      "sats": 5607542,
      "btc": 0.05607542
  }


totalSpent
0.06901843