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-590-630-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
630
+
631
+
..code-block::javascript
632
+
633
+
// assets/controllers/user-list-controller.js
634
+
importusersPromisefrom'../data/users.json';
635
+
636
+
asyncfunctiondisplayUsers() {
637
+
constuserData=await usersPromise;
638
+
639
+
userData.users.forEach(user=> {
640
+
console.log(`${user.name}:${user.email}`);
641
+
});
642
+
}
643
+
644
+
displayUsers();
645
+
646
+
How it Works
647
+
~~~~~~~~~~~~
648
+
649
+
When you import a JSON file, AssetMapper:
650
+
651
+
1. **Detects the JSON import** in your JavaScript files during asset processing
652
+
2. **Creates a JavaScript module** that exports a Promise resolving to the JSON content
653
+
3. **Adds it to the importmap** so your browser can locate and load it correctly
654
+
4. **Versions the file** like any other asset, ensuring proper cache busting
655
+
656
+
This approach works in all modern browsers without requiring native JSON import
657
+
support, making it a reliable alternative to the newer ``with { type: 'json' }``
658
+
syntax.
659
+
660
+
..note::
661
+
662
+
Like CSS imports, JSON imports are processed by AssetMapper and added to the
663
+
importmap automatically. The imported JSON assets are also versioned, so any
664
+
changes to the JSON content will result in a new versioned filename.