# import

Learn how to load and evaluate a JSON file relative to the template.

Loads a JSON or JSON5 file relative to the template location, evaluates any [expressions](/reference/cli/templates/expressions) in it, and returns the result.

Parameters passed via the second argument are merged into the [`this`](/reference/cli/templates/variables#this-prop) context of the imported file, so the imported file can reference them using `${this.paramName}`.

> **Scope inheritance**
>
> Imported files have full access to all parent variables like `options`, `project`, and `packageManager`. The `params` parameter only adds or overrides keys within `this` — it does not restrict the scope.

## Example

Given a file that defines a print action using both a parameter and a parent variable:

**actions/welcome.json5**

```json5
{
  "name": "print",
  "semantics": "success",
  // `this.greeting` comes from the parent scope, `this.name` from params
  "message": "${this.greeting}, ${this.name}!"
}
```

A template can define a variable and then import the file, passing additional parameters:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Greeter",
  "description": "Prints a welcome message.",
  "actions": [
    {
      "name": "define",
      "variables": {
        "greeting": "Welcome"
      }
    },
    "${import('./actions/welcome.json5', {name: 'Alice'})}"
  ]
}
```

Running this template prints `Welcome, Alice!`. The imported file sees `this.greeting` from the parent scope and `this.name` from the params.

## Parameters

- `path`: `string`

  The path to the JSON file, relative to the template.

- `params`: `object` (optional)

  Key-value pairs merged into the `this` context when evaluating the imported file. This is how you pass data from the parent template to the imported file.

## Return

The evaluated content of the JSON file.

The return type depends on the file content and can be an object, array, string, or any valid JSON value.

## Explore

- [Import](/reference/cli/templates/actions/import): Learn how to import and execute another template.
- [Variables](/reference/cli/templates/variables): Explore the built-in template variables.
