---
title: "lzb/import_json"
description: "PHP filter `lzb/import_json` of the Lazy Blocks WordPress plugin."
url: "https://www.lazyblocks.com/docs/php-filters/lzb-import_json/"
source: "php-filters/lzb-import_json.mdx"
---
# lzb/import_json

Filters the decoded contents of an export file before Lazy Blocks creates any posts from it.

An export file produced on a staging site carries that site's category slugs and post types. Rewrite them here, or drop the items you do not want to land, without editing the JSON by hand before every import.

## Attributes

| Name    | Type      | Description                                             |
| ------- | --------- | ------------------------------------------------------- |
| `$json` | **Array** | decoded export file, a list of block and template items |

Each item needs an `id` key or the import loop skips it. Lazy Blocks decides what an item is by its other keys:

| Item     | Recognised by                                     | Handled by                                                                                          |
| -------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| block    | any of `icon`, `category`, `supports`, `controls` | `import_block()`, which then fires [lzb/import/block](https://www.lazyblocks.com/docs/php-actions/lzb-import-block/)          |
| template | `post_types`                                      | `import_template()`, which then fires [lzb/import/template](https://www.lazyblocks.com/docs/php-actions/lzb-import-template/) |

The filter runs after the nonce, file size, upload error, `.json` extension and non-empty-array checks have all passed, so a handler never sees a rejected upload.

## Usage

```php title="PHP"
function my_lzb_import_json( $json ) {
  foreach ( $json as $k => $data ) {
    // Blocks exported from staging carry its category. Put them in ours.
    if ( isset( $data['controls'] ) && isset( $data['category'] ) ) {
      $json[ $k ]['category']       = 'theme-blocks';
      $json[ $k ]['category_label'] = 'Theme Blocks';
    }
  }

  return $json;
}

add_filter( 'lzb/import_json', 'my_lzb_import_json' );
```

Returning anything but an array raises a `TypeError` at the `foreach` that follows. Returning an empty array imports nothing and shows no notice, because the success notices are built from the list of created post IDs. Lazy Blocks keeps its own callback here at priority 10, converting any pre-2.5.0 template item that still has a `data` sub-array.

The screen this runs behind is [Export / Import](https://www.lazyblocks.com/docs/export-blocks/).

## 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
