Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using JSON files in vanilla websites #102

Open
sanjarcode opened this issue Oct 28, 2023 · 2 comments
Open

Using JSON files in vanilla websites #102

sanjarcode opened this issue Oct 28, 2023 · 2 comments

Comments

@sanjarcode
Copy link
Member

sanjarcode commented Oct 28, 2023

  1. Node - require works. import works too, but might need assert JSON.
  2. Browser (vanilla) - fetch('./path-to-file') is simplest way that works for all browsers. FYI, import (with assert JSON) works on Chrome, but fails on Firefox or Safari.
  3. Browser with bundlers - import data from "data.json" works fine.

On web, prefer using this wrapper

async function fetchJSON(pathToFile) {
  const resp = await fetch(pathToFile);
  const jsonFileAsObject = await resp.json();
  return jsonFileAsObject;
}
@sanjarcode
Copy link
Member Author

Related:

@sanjarcode
Copy link
Member Author

sanjarcode commented Feb 14, 2024

A more specific proposal of the above is in place to solve this. Will be released in 2024 hopefully. Current support is almost zero. See

Syntax is the same, with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant