Skip to content

Rule examples

Krzysztof Słysz edited this page Dec 7, 2021 · 5 revisions

Rule examples

Example 1.

Rules for data where id > 0:

{
  "rules": [
    ["id", ">", 0]
  ]
}

Example 2.

Rules for data where tagId == 5:

{
  "rules": [
    ["tagId", "==", 5]
  ]
}

Example 3.

Rules for data where owner contains "robot":

{
  "rules": [
    ["owner", "like", "%admin%"]
  ]
}

Example 4.

Rules for only reserved data:

{
  "rules": [
    ["reserved", "==", true]
  ]
}

Example 5.

Rules for data where properties does not contain "black":

{
  "rules": [
    ["properties", "!like", "%black%"]
  ]
}

Example 6.

Data is created by "userA" or "userB":

{
  "rules": [
    ["createdBy", "in", ["userA", "userB"]]
  ]
}

Example 7.

Date "execution" is after or equal first of January 2000, 14:30 (expected Zulu time):

{
  "rules": [
    ["$.execution", ">=", "2000-01-01T14:30:00.000Z"]	
  ]
}

Example 8.

Rules for data where the property "$.oboarded" exists and the value is true:

{
  "rules": [
    ["$.onboarded.exists()", "==", true],
    ["$.onboarded", "==", true]
  ]
}

Example 9.

Rules for data where the property "$.name" matches regular expression, case insensitively:

{
  "rules": [
    ["$.name", "~*", "j.*n"]
  ]
}

Example 10.

Rules for data where the property "$.name" does not contain a, b or c character:

{
  "rules": [
    ["$.name", "!similar", "%(a|b|c)%"]
  ]
}

Example 11.

Rules for data where the property "$.purchaseDate" is less than current date minus one day:

{
  "rules": [
    ["$.purchaseDate::timestamp", "<", "#func:NOW() - INTERVAL '1 DAY'"]
  ]
}