JSON conditions and Claimable Benefits

Format

All JSON blocks follow this format:
Apply the benefit / award when a profile meets this condition.

Operators

In this document we will run through single, OR, AND examples.
You can use any JSON Logic operators seen here (http://jsonlogic.com)

Single Condition

People Called John

{ "===" : [{"var": "first_name"}, "John"] }

Either (or) Condition

When profile has tag 1, or tag 2

{
  "or": [
    {
      "in": [
        "tag-1",
        {
          "var": "flattened_tags"
        }
      ]
    },
    {
      "in": [
        "tag-2",
        {
          "var": "flattened_tags"
        }
      ]
    }
  ]
}

More than one condition (and)

When birth year is less than 1980 and tier is 2

{
  "and": [
    {
      "<": [
        {
          "var": "birth_year"
        },
        1980
      ]
    },
    {
      "==": [
        {
          "var": "tier_handle"
        },
        "tier_2"
      ]
    }
  ]
}

Example 2

{
  "and": [
    {
      ">": [
        {
          "var": "aggregations.spend_12m"
        },
        1000
      ]
    },
    {
      "==": [
        {
          "var": "tier_handle"
        },
        "tier_2"
      ]
    }
  ]
}

Example: Multiple NOT conditions (e.g. multiple profile attributes not equal to a value)

This example will check if either tag-1 or tag-2 are present on the profile. If any tag is present, the condition will exclude the profile from claiming the benefit.

{
	"and": [
		{
			"!": {"in": ["tag-1", {"var": "flattened_tags"}]}
		},
		{
			"!": {"in": ["tag-2", {"var": "flattened_tags"}]}
		}
	]
}

Example: Single NOT condition (e.g. attribute not equal to a value)

This example will check if tag-1 is present on the profile. If it is present the profile will not be able to claim the benefit.

{
	"!": {"in": ["tag-1", {"var": "flattened_tags"}]}
}

Fields available

The fields you can call or place logic conditions on are as follows.

Level 1: Any profile field

Fields are already oriented to Profiles. So to call a profiles example_field you won't need profiles.example_field. Rather you should simply use example_field.
including:

{
  "id": "8fc344db-713e-4590-ab26-e82d77ba3313",
  "external_id": null,
  "title": null,
  "first_name": "Drewtest",
  "last_name": "Test",
  "full_name": "Drewtest Test",
  "email": "[email protected]",
  "gender": null,
  "currency": null,
  "mobile_phone": null,
  "mobile_phone_country": null,
  "mobile_phone_e164": null,
  "mobile_phone_national": "",
  "secondary_phone": null,
  "birth_year": null,
  "birth_month": null,
  "birth_day": null,
  "company": null,
  "occupation": null,
  "avatar_url": null,
  "joined_at": "2020-02-03 00:05:51",
  "joined_location_id": null,
  "preferred_location_id": null,
  "joined_location": null,
  "preferred_location": null,
  "tags": [],
  "flattened_tags": [],
  "flattened_statuses": [],
  "tier_handle": "3-star",
  "birth_date": null,
  "next_birthday": null,
  "birth_days": null,
  "birth_days_past": null,
  "custom_attributes": [],
  "statuses": [],
  "address": null,
  "addresses": [],
  "reward_balance": 0,
  "point_balance": 0,
  "combined_balance_dollars": 0,
  "point_balance_dollars": 0,
  "created_at": "2020-02-03 00:06:06",
  "updated_at": "2020-02-03 00:06:11",
  "changes": []
}

level 2

second level context. I.e. if in identities then use identities.field
Including:

"tier": {
        "handle": "3-star",
        "name": "★★★"
    },
 "aggregations": {
        "id": 790,
        "profile_id": "8fc344db-713e-4590-ab26-e82d77ba3313",
        "shop_days": 0,
        "spend_12m": 22660,
        "spend_all": 22660,
        "spend_atv_12m": 3237.14,
        "spend_atv_all": 3237.14,
        "spend_first_date": "2019-07-07 22:19:01",
        "spend_last_date": "2019-07-07 22:19:01",
        "dimension_join": "JN",
        "dimension_channel": null,
        "dimension_frequency": "FH",
        "dimension_recency": "RA",
 "originals": {
        "id": "8fc344db-713e-4590-ab26-e82d77ba3313",
        "user_id": null,
        "preferred_location_id": null,
        "joined_location_id": null,
        "title": null,
        "first_name": "Drewtest",
        "last_name": "Test",
        "email": "[email protected]",
        "gender": null,
        "is_completed": 1,
        "currency": null,
        "joined_at": "2020-02-03 00:05:51",
        "mobile_phone": null,
        "birth_day": null,
        "birth_month": null,
        "birth_year": null,
        "next_birthday": null,
        "company": null,
        "occupation": null,
        "avatar_url": null,
        "deleted_at": null,
        "created_at": "2020-02-03 00:06:06",
        "updated_at": "2020-02-03 00:06:11",
        "secondary_phone": null
    },

Level 3

These are fields that are nested three levels. I.e. to find example_field use location.location.example_field

Including

"attributes": {
        "comms": {
            "profile_id": "8fc344db-713e-4590-ab26-e82d77ba3313",
            "email_optout": false,
            "sms_optout": false,
            "push_optout": false,
            "phone_optout": false,
            "post_optout": false,
            "email_bounced": false,
            "push_bounced": false,
            "sms_bounced": false,
            "phone_bounced": false,
            "post_bounced": false,
            "sms_promo": false,
            "push_promo": true,
            "email_promo": true,
            "phone_promo": false,
            "post_promo": false,
            "email_discover": true,
            "email_benefits": true,
            "email_reminders": true,
            "email_account": true,
            "email_bookings": true,
            "email_feedback": true,
            "email_location": false,
            "email_service": true,
            "sms_discover": false,
            "sms_benefits": false,
            "sms_reminders": true,
            "sms_account": false,
            "sms_bookings": true,
            "sms_feedback": false,
            "sms_location": false,
            "sms_service": true,
            "push_discover": true,
            "push_benefits": true,
            "push_reminders": true,
            "push_account": true,
            "push_bookings": true,
            "push_feedback": true,
            "push_location": true,
            "push_service": true,
            "phone_discover": true,
            "phone_benefits": true,
            "phone_reminders": true,
            "phone_account": true,
            "phone_bookings": true,
            "phone_feedback": true,
            "phone_location": true,
            "phone_service": true,
            "post_discover": true,
            "post_benefits": true,
            "post_reminders": true,
            "post_account": true,
            "post_bookings": true,
            "post_feedback": true,
            "post_location": true,
            "post_service": true,
            "email_verification": "not_sent",
            "sms_verification": "not_sent",
            "phone_verification": "not_sent",
            "post_verification": "not_sent",
            "created_at": "2020-02-03 00:06:06",
            "updated_at": "2020-02-03 00:06:06"
        },
        "appearance": {
            "profile_id": "8fc344db-713e-4590-ab26-e82d77ba3313",
            "hair_colour": null,
            "hair_length": null,
            "shape_body": null,
            "shape_face": null,
            "size_cup": null,
            "size_hat": null,
            "size_formal_jacket": null,
            "size_formal_jacket_length": null,
            "size_formal_shirt": null,
            "size_formal_shirt_fit": null,
            "size_formal_trouser": null,
            "size_formal_trouser_drop": null,
            "size_formal_trouser_leg": null,
            "size_jacket": null,
            "size_pant": null,
            "size_shoe": null,
            "size_type_age": null,
            "size_type_region": null,
            "size_top": null,
            "skin_type": null,
            "measurement_arm": null,
            "measurement_arm_inside": null,
            "measurement_bust": null,
            "measurement_chest": null,
            "measurement_foot_length": null,
            "measurement_head": null,
            "measurement_height": null,
            "measurement_hip": null,
            "measurement_leg_inside": null,
            "measurement_leg_outside": null,
            "measurement_neck": null,
            "measurement_neck_to_wrist": null,
            "measurement_shoulders": null,
            "measurement_waist": null,
            "measurement_weight": null,
            "created_at": "2020-02-03 00:06:06",
            "updated_at": "2020-02-03 00:06:06"
        },
 "aggregations": {
        "id": 790,
        "profile_id": "8fc344db-713e-4590-ab26-e82d77ba3313",
        "shop_days": 0,
        "spend_12m": 22660,
        "spend_all": 22660,
        "spend_atv_12m": 3237.14,
        "spend_atv_all": 3237.14,
        "spend_first_date": "2019-07-07 22:19:01",
        "spend_last_date": "2019-07-07 22:19:01",
        "dimension_join": "JN",
        "dimension_channel": null,
        "dimension_frequency": "FH",
        "dimension_recency": "RA",
        "most_transacted_location": {
            "id": 15,
            "name": null,
            "external_id": "M01",
            "external_code": null,
            "custom_fields": [],
            "created_at": "2019-12-13 03:13:04",
            "updated_at": "2019-12-13 03:13:04"
        },
        "store_join": {
            "id": 15,
            "name": null,
            "external_id": "M01",
            "external_code": null,
            "custom_fields": [],
            "created_at": "2019-12-13 03:13:04",
            "updated_at": "2019-12-13 03:13:04"
        },
        "likely_country": null,
        "likely_country_score": null,
        "purchased_brands": [
            "lancome"
        ],
        "shop_count": 7,
        "created_at": "2020-02-03 00:06:06",
        "updated_at": "2020-02-03 00:53:01"
    }