import json data into a JS module

PHOTO EMBED

Sun Jul 23 2023 00:55:56 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #javascript #module #json #data #import

// file data.json

{
"localItems": {
	"items": [
      {
		"title": "Halabut",
		"type": "string",
        "status": false
		},
			{
        "title": "Taco",
		"type": "string",
        "status": true
		},
      {
        "title": "Fish",
		"type": "string",
        "status": true
		},
      {
        "title": "Pork",
		"type": "string",
        "status": false
		}
		]
	}
}




//js file must be a module
// <script src="scripts.js" defer type="module"></script>

// JS file 
import data from "./data.json" assert { type: "json" };
const {localItems} = data;
const JSONDATA = localItems['items'];

content_copyCOPY

importing json data directly into a JS file