Error With Parsing JSON

So, I am making a Trivia App that you will be able to make your own question sets in HTML/CSS/JS, I am planning on putting my question set data into a JSON file, but when I try and fetch and parse the data in my JavaScript file it throws this error →

Error: Cannot parse given Error object 

Repl link:


import data from './question_sets.json';

const question_sets = data;

let answer;

function set_question() {
    let random = Math.floor(Math.random() * question_sets.planetary_set.length);
    let question = question_sets.planetary_set[random].question;
    answer = question_sets.planetary_set[random].answer;
    let icon = question_sets.planetary_set[random].icon;
    let type = question_sets.planetary_set[random].type;

    document.getElementById("icon").setAttribute("name", icon);
    document.getElementById("icon").setAttribute("type", type);
    document.getElementById("question").innerHTML = question;


let modal = document.getElementById("question-modal");

let modal_text = document.getElementById("modal-text");

document.querySelector('.q-a-wrapper').addEventListener('submit', function(event) {

    let answer_input = document.getElementById("answer-input");
    let answer_value = answer_input.value.toLowerCase();

    if (answer_value) { = "1";
        if (answer_value === answer.toLowerCase()) {
            modal_text.innerHTML = "Correct";
   = "var(--back)";
   = "var(--primary)";
        } else {
            modal_text.innerHTML = "Incorrect";
   = "var(--fore)";
   = "var(--back)";
        answer_input.value = '';


        setTimeout(function() {
   = "0";
            setTimeout(function() {
            }, 300);
        }, 2000);



    "planetary_set": [
            "question":"What is the 1st planet from the Sun?",
            "question":"What is the most common element in the universe?",
            "question":"What unkown force is causing the universe to expand?",
            "answer":"dark energy",

Tbh that looks kinda like it’s just the devtools wrapper being a pain…

Does it work in a new tab? If not, it should at least provide a more helpful error.

No it doesn’t. I wonder what it is then, I am new to JS so I might have just done some small mistake to cause it.

Does it still throw the same error?

Also wait, I get an entirely different error from your code…

@Firepup650 the error stopped after I put changed the <script> tag to <script type="module" src="script.js"></script> .

1 Like

3 posts were split to a new topic: JavaScript Not Running/Displaying

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.