# metafield

> The metafield Liquid object in a Shoplazza theme, and how to access the metafields of a parent object, including object-type and typed metafields.

A metafield attached to a parent object.

To learn about how to access a metafield on a specific object, refer to [Access metafields](./metafield#access-metafields).

| Properties | Description                 |
| :--------- | :-------------------------- |
| `value`    | The value of the metafield. |

The following table outlines the value format for each metafield type:

  
    
      
        Type
      

      
        Returned format
      
    
  

  
    
      
        `single_line_text_field`  

        `multi_line_text_field`
      

      
        [A string](../basics/liquid-types#string)
      
    

    
      
        `product_reference`
      

      
        [A product object](./product)
      
    

    
      
        `collection_reference`
      

      
        [A collection object](./collection)
      
    

    
      
        `file_reference`
      

      
        [A image object](./image)
      
    

    
      
        `number_integer`  

        `number_decimal`
      

      
        [A number](../basics/liquid-types#number)
      
    

    
      
        `date`  

        `date_time`
      

      
        [A date string](../basics/liquid-types#string)
      
    

    
      
        `url`
      

      
        [A URL string](../basics/liquid-types#string)
      
    

    
      
        `json`
      

      
        [A JSON object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON)
      
    

    
      
        `boolean`
      

      
        [A boolean](../basics/liquid-types#boolean)
      
    

    
      
        `color`
      

      
        [A color string](../basics/liquid-types#string)
      
    

    
      
        `weight`  

        `volume`  

        `dimension`
      

      
        [A measurement object](./measurement)
      
    

    
      
        `rating`
      

      
        [A rating object](./rating)
      
    
  

## Access metafields

The access path for metafields consists of two layers:

* `namespace` - A grouping of metafields to prevent conflicts.
* `key` - The metafield name.

Given this, you can access the metafield object with the following syntax:

```liquid
{{ resource.metafields.namespace.key }}
```

```liquid title="Code"
{{ product.metafields.custom.directions.value }}
```

```html title="Output"
Take with a meal
```

## Accessing metafields of type

The `value` property of metafields of type `json` returns a [JSON object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON). You can access the properties of this object directly in Liquid, either by name or 0-based index. You can also iterate through the properties.

```liquid title="Code"
Temperature: {{ product.metafields.custom.burn_temperature.value.temperature }}

Unit: {{ product.metafields.custom.burn_temperature.value['unit'] }}

{% for property in product.metafields.custom.burn_temperature.value %}
  {{ property[0] | capitalize }}: {{ property[1] }}
{% endfor %}
```

```html title="Output"
Temperature: 700

Unit: degrees

Temperature: 700
Unit: degrees
Scale: Fahrenheit
```

## Accessing object-type metafields

Some metafield types return an object. Access the nested data through the `value` property.

A `file_reference` (image) metafield exposes the file under `value`. Read the image through `value.image`, or pass `value` to the [`img_url`](../filters/media#img_url) filter:

```liquid title="Code"
{{ product.metafields.custom.spec_file.value.image.src }}

{{ product.metafields.custom.spec_file.value | img_url: '200x' }}
```

A `weight`, `volume`, or `dimension` metafield returns a [measurement object](./measurement):

```liquid title="Code"
{{ product.metafields.custom.net_weight.value.value }} {{ product.metafields.custom.net_weight.value.unit }}
```

```html title="Output"
20 KILOGRAMS
```

A `rating` metafield returns a [rating object](./rating):

```liquid title="Code"
{{ product.metafields.custom.review_score.value.value }} / {{ product.metafields.custom.review_score.value.scale_max }}
```

```html title="Output"
4 / 10.0
```

:::tip
Accessing a metafield always returns a metafield object — even when the metafield isn't defined, the result isn't `nil`. To check whether a value is present, test `value`, for example `{% if product.metafields.custom.spec_text.value != blank %}`.
:::
