You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
You can import and use this data in your #"diff-a2220159377c0de535d5b1a19b871634733fca70a11805935ab2867be27e8dac-512-552-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
552
+
553
+
..code-block::javascript
554
+
555
+
// assets/controllers/user-list-controller.js
556
+
importusersPromisefrom'../data/users.json';
557
+
558
+
asyncfunctiondisplayUsers() {
559
+
constuserData=await usersPromise;
560
+
561
+
userData.users.forEach(user=> {
562
+
console.log(`${user.name}:${user.email}`);
563
+
});
564
+
}
565
+
566
+
displayUsers();
567
+
568
+
How it Works
569
+
~~~~~~~~~~~~
570
+
571
+
When you import a JSON file, AssetMapper:
572
+
573
+
1. **Detects the JSON import** in your JavaScript files during asset processing
574
+
2. **Creates a JavaScript module** that exports a Promise resolving to the JSON content
575
+
3. **Adds it to the importmap** so your browser can locate and load it correctly
576
+
4. **Versions the file** like any other asset, ensuring proper cache busting
577
+
578
+
This approach works in all modern browsers without requiring native JSON import
579
+
support, making it a reliable alternative to the newer ``with { type: 'json' }``
580
+
syntax.
581
+
582
+
..note::
583
+
584
+
Like CSS imports, JSON imports are processed by AssetMapper and added to the
585
+
importmap automatically. The imported JSON assets are also versioned, so any
586
+
changes to the JSON content will result in a new versioned filename.