> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt
> Use this file to discover all available pages before exploring further.

# Import Assertions to Attributes

> Convert import assertions (assert) to standardized import attributes (with) syntax

This recipe converts import assertions (`assert` syntax) to the standardized import attributes (`with` syntax) for importing JSON and other module types.

## Background

Node.js dropped support for import assertions in favor of import attributes in version [22.0.0](https://nodejs.org/fr/blog/release/v22.0.0#other-notable-changes). The new syntax uses `with` instead of `assert` to align with the ECMAScript standard.

Import attributes were added in Node.js version [18.20.0](https://nodejs.org/fr/blog/release/v18.20.0#added-support-for-import-attributes).

## Usage

Run this codemod with:

```bash theme={null}
npx codemod nodejs/import-assertions-to-attributes
```

## Before/After

```diff theme={null}
- import data from './data.json' assert { type: 'json' };
+ import data from './data.json' with { type: 'json' };
```

## What It Does

* Replaces `assert { type: 'json' }` with `with { type: 'json' }`
* Updates both static and dynamic imports
* Preserves import path and other syntax

## When to Use This

Use this codemod when:

* Upgrading to Node.js 22 or later
* Your codebase uses import assertions for JSON modules
* You want to adopt the standardized ECMAScript syntax

## Example Scenarios

### JSON Imports

```diff theme={null}
- import config from './config.json' assert { type: 'json' };
+ import config from './config.json' with { type: 'json' };
```

### Dynamic Imports

```diff theme={null}
- const data = await import('./data.json', { assert: { type: 'json' } });
+ const data = await import('./data.json', { with: { type: 'json' } });
```

<Warning>
  Import assertions are completely removed in Node.js 22. If you're running Node.js 22+, your code will fail without this migration.
</Warning>

<Tip>
  The `with` keyword is the standard syntax across all JavaScript runtimes. Migrating now ensures better cross-runtime compatibility.
</Tip>
