DataJet
  • Welcome to DataJet
  • Scripts
    • Introduction
    • Scripts
      • Input
      • HTTP
      • Scheduled
      • Event
      • Shipping Rate
      • Email
    • Creating a custom script
  • Liquid
    • Introduction
    • Tags
      • exit
      • function
      • json
      • push
      • run
    • Filters
      • array_difference
      • array_equal
      • array_intersection
      • array_symmetric_difference
      • base64_decode
      • base64_encode
      • concat
      • content
      • email
      • encode_uri
      • file
        • multipart
        • url
        • content
      • find
      • find_exp
      • flat
      • flow
      • flow_v2
      • ftp
      • graphql
      • group_by
      • group_by_exp
      • hmac_sha256
      • http
      • in_groups_of
      • in_timezone
      • log
      • parse_json
      • parse_csv
      • parse_xml
      • pop
      • push
      • random
      • remove_prop
      • rest
      • run
      • sha1
      • sum
      • time_add
      • time_subtract
      • type
      • where_exp
  • Misc
    • Credits and usage
    • GitHub Integration
      • Track changes in a script's source code
      • Connect development stores with development branches
      • Use one codebase across multiple Shopify stores
    • Functions
    • Variables
    • Shopify Flow Integration
      • V1
      • V2
    • Processing user submitted forms
Powered by GitBook
On this page
  1. Liquid
  2. Filters

group_by_exp

Groups an array elements based on item property value meeting given condition

{% json employees %}
  [
    {
      "first_name": "Ann",
      "last_name": "Smith",
      "position": "Accountant",
      "city": "New York",
      "age": 25
    },
    {
      "first_name": "Adam",
      "last_name": "Fox",
      "position": "Salesman",
      "city": "New Jersey",
      "age": 35
    },
    {
      "first_name": "Angela",
      "last_name": "Newman",
      "position": "Accountant",
      "city": "Boston",
      "age": 43
    }
  ]
{% endjson %}
{% assign group_by_exp_age_result = employees | group_by_exp: "item", "item.age >= 30" %}
{{ group_by_exp_age_result | log }}

Results in following array logged to console:

[
  {
    "name": false,
    "items": [
      {
        "first_name": "Ann",
        "last_name": "Smith",
        "position": "Accountant",
        "city": "New York",
        "age": 25
      }
    ]
  },
  {
    "name": true,
    "items": [
      {
        "first_name": "Adam",
        "last_name": "Fox",
        "position": "Salesman",
        "city": "New Jersey",
        "age": 35
      },
      {
        "first_name": "Angela",
        "last_name": "Newman",
        "position": "Accountant",
        "city": "Boston",
        "age": 43
      }
    ]
  }
]
Previousgroup_byNexthmac_sha256

Last updated 7 months ago