/json-import

a test of how we can import JSON in september 2018

Primary LanguageHTMLMIT LicenseMIT

json-import

a test of how we can import JSON in september 2018.

requirements

start

yarn install
yarn start

server will be listening on http://127.0.0.1:8080

tested

fetch('/data.json')
  .then(response => response.json())
  .then(json => console.log(json))
  • Present in all browsers > IE11. See caniuse
  • Can't import JSON file
  • Have to add the type="module" attribute on the script tag
  • No real polyfill
import json from '/data.js'
console.log(json)

using a bundler (parcel in this case)

  • Work in all browsers
  • Can import json
  • Add a build step
import json from '../public/data.json'
console.log(json)