I have a file Json_data.txt
which is stored locally. The content of the file is a JSON object as given below:
{
"directed": "true",
"multigraph": "true",
"graph": {"directed": "true"},
"nodes": [
{"id": "Brave Browser", "shape": "circle"},
{"id": "Windows Explorer", "shape": "circle"},
{"id": "Spotify", "shape": "circle"},
{"id": "Windows Shell Experience Host", "shape": "circle"},
{"id": "Timeular", "shape": "circle"}
],
"links": [
{"source": "Brave Browser", "target": "Brave Browser", "time": 4, "weight": 4},
{"source": "Brave Browser", "target": "Windows Explorer", "time": 2, "weight": 2},
{"source": "Windows Explorer", "target": "Spotify", "time": 1, "weight": 1},
{"source": "Spotify", "target": "Spotify", "time": 1, "weight": 1},
{"source": "Spotify", "target": "Windows Explorer", "time": 1, "weight": 1},
{"source": "Windows Explorer", "target": "Windows Shell Experience Host", "time": 1, "weight": 1},
{"source": "Windows Shell Experience Host", "target": "Brave Browser", "time": 1, "weight": 1},
{"source": "Windows Explorer", "target": "Timeular", "time": 1, "weight": 1},
{"source": "Timeular", "target": "Timeular", "time": 1, "weight": 1},
{"source": "Timeular", "target": "Brave Browser", "time": 1, "weight": 1}
]
}
I am trying to read the above JSON in the HTML page for further processing. I tried using src
in the script tag to link the file and tried to parse it as "script type="text/javascript" src="file:///C:/file_path/Json_data.txt"
. I am trying to get the content into test
:
fetch('file:///C:/file_path/Json_data.txt')
.then(response => response.json())
.then(test => JSON.parse(json));
The above code is not working. Could anyone please tell me what am I doing wrong here?