---
title: "lzb.editor.control.getValue"
description: "lzb.editor.control.getValue turns what is stored for a control into what its editor component expects. Use it to parse a custom control's JSON value."
url: "https://www.lazyblocks.com/docs/js-filters/lzb-editor-control-getvalue/"
lastUpdated: 2026-09-23
source: "js-filters/lzb-editor-control-getvalue.mdx"
---
# lzb.editor.control.getValue

Turns what is stored for a control into what its editor component expects. This is the first of three filters a value passes through in the editor: `getValue` on the way in, [lzb.editor.control.validate](https://www.lazyblocks.com/docs/js-filters/lzb-editor-control-validate/) before the post can be saved, and [lzb.editor.control.updateValue](https://www.lazyblocks.com/docs/js-filters/lzb-editor-control-updatevalue/) on the way back out.

The plugin has already picked the raw value by the time the filter runs. It comes from `attributes[control.name]`, or from `meta[control.save_in_meta_name || control.name]` when the control has `save_in_meta` set to `true`, or from the parent's array at `childIndex` when the control lives inside a repeater.

## Attributes

| Name         | Type                  | Description                                                                                   |
| ------------ | --------------------- | --------------------------------------------------------------------------------------------- |
| `val`        | **Mixed**             | the stored value, before any coercion                                                         |
| `control`    | **Object**            | control settings: `type`, `name`, `default`, `label`, `child_of`, `save_in_meta` and the rest |
| `childIndex` | **Number \| Boolean** | row index inside a repeater, otherwise `false` or `undefined`                                 |

## Additional Filters

| Name                                       | Description            |
| ------------------------------------------ | ---------------------- |
| `lzb.editor.control.CONTROL_TYPE.getValue` | specific controls only |

The type-specific filter runs first and the generic one runs on its result.

## Usage

```js title="JS"
wp.hooks.addFilter(
  "lzb.editor.control.getValue",
  "my.custom.namespace",
  function (val, control) {
    if (control.type !== "my_json") {
      return val;
    }

    try {
      return JSON.parse(val || "{}");
    } catch (e) {
      return {};
    }
  },
);
```

After both filters, an `undefined` result is replaced with an empty string, so a handler cannot use `undefined` to mean "leave the stored value alone". Whatever shape you return here has to survive the trip back through [lzb.editor.control.updateValue](https://www.lazyblocks.com/docs/js-filters/lzb-editor-control-updatevalue/), which is where the value is turned back into something the block attribute or the post meta can hold.

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
