How can I use JavaScript to load a JSON file from my desktop? or What's the best way to load a JSON f

14 Replies, 1327 Views

lol not a dumb question at all! CORS blocks fetch from loading local files for security reasons.

If you *really* don’t wanna use a server, you could try the `--allow-file-access-from-files` flag in Chrome, but it’s messy and not recommended.

Another hacky way: convert your JSON to a JS object and just `import` it. Like, rename `data.json` to `data.js` and do:
```js
const data = { "your": "json", "here" }; // in data.js
import { data } from './data.js';
```
But yeah, a local server is the cleanest solution.

Messages In This Thread



Users browsing this thread: 1 Guest(s)