Homepage

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 %}x is a number
  • {% assign x = "hello" %}x is a string
  • {% assign x = true %}x is a boolean
  • {% assign x = arr | split: "," %}x is an array
  • {% assign x = json | parse_json %} or {% parse_json x %}x is an object
  • {% graphql x = 'query' %}x is 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.

Resources

Questions?

We are always happy to help with any questions you may have.

contact us