InvalidHashAssignTarget
Last edit: Apr 01, 2026
InvalidHashAssignTarget
Severity: error | Type: LiquidHtml
This check reports errors when {% hash_assign %} is used on a variable that has been inferred to be a primitive type (number, string, boolean) or an array. The hash_assign tag is only valid on object (hash) types.
The check infers variable types from how they are assigned:
{% assign x = 1 %}—xis a number{% assign x = "hello" %}—xis a string{% assign x = true %}—xis a boolean{% assign x = arr | split: "," %}—xis an array{% assign x = json | parse_json %}or{% parse_json x %}—xis an object{% graphql x = 'query' %}—xis an object
Examples
✗ Incorrect Code Example (Avoid using this):
{% assign counter = 0 %}
{% hash_assign counter['key'] = "value" %}
counter is a number, so hash_assign cannot be used on it.
{% assign items = "a,b,c" | split: "," %}
{% hash_assign items['key'] = "value" %}
items is an array, so hash_assign cannot be used on it.
✓ Correct Code Example (Use this instead):
{% assign data = '{}' | parse_json %}
{% hash_assign data['key'] = "value" %}
{% parse_json data %}{}{% endparse_json %}
{% hash_assign data['key'] = "value" %}
Configuration
The default configuration for this check:
InvalidHashAssignTarget:
enabled: true
severity: error
Disabling This Check
Disabling this check is not recommended.