Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hiswe/json-import
a test of how we can import JSON in september 2018
https://github.com/hiswe/json-import
Last synced: 30 days ago
JSON representation
a test of how we can import JSON in september 2018
- Host: GitHub
- URL: https://github.com/hiswe/json-import
- Owner: Hiswe
- License: mit
- Created: 2018-09-18T04:44:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-04T11:39:31.000Z (almost 3 years ago)
- Last Synced: 2024-04-13T12:13:56.427Z (9 months ago)
- Language: HTML
- Homepage:
- Size: 73.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-import
a test of how we can import JSON in september 2018.
- [requirements](#requirements)
- [start](#start)
- [tested](#tested)
- [fetch](#fetch)
- [import](#import)
- [using a bundler (parcel in this case)](#using-a-bundler-parcel-in-this-case)## requirements
- [node](http://nodejs.org/download/) >= 8.12.0
- [yarn](https://yarnpkg.com/lang/en/) >= 1.9.4## start
```
yarn install
yarn start
```server will be listening on http://127.0.0.1:8080
## tested
### [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
- Present in all browsers > IE11. See [caniuse](https://caniuse.com/#search=fetch)
- Replacement of XMLHttpRequest.
- Can use a [unfetch polyfill](https://github.com/developit/unfetch)```js
fetch('/data.json')
.then(response => response.json())
.then(json => console.log(json))
```### [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)
- Present in all browsers > IE11. See [caniuse](https://caniuse.com/#search=module)
- Can't import JSON file
- Have to add the `type="module"` attribute on the script tag
- No [real polyfill](https://github.com/ModuleLoader/browser-es-module-loader)```js
import json from '/data.js'
console.log(json)
```### using a bundler ([parcel](https://parceljs.org/) in this case)
- Work in all browsers
- Can import json
- Add a build step```js
import json from '../public/data.json'
console.log(json)
```