For my project, I am using the python SimpleHTTPWebserver to serve up various files, including a valid JSON file named "file.json". In my javascript front end, I need to interpret this JSON object as an array of arrays. For example:
{
"val1": 101,
"val2": 202
}
Should be transformed into
var jsonFile = [['val1', 101], ['val2', 202]]
Unfortunately, I am unable to even load the file's raw content into a variable. I am new to javascript and have attempted the following:
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js" charset="utf-8"></script>
</head>
<body></body>
<script type="text/javascript">
var mydata = JSON.parse("file.json");
</script>
</html>
However, this code snippet is throwing an error:
VM89:1 Uncaught SyntaxError: Unexpected token s in JSON at position 0 at JSON.parse () at :1:6
Being new to javascript, I want to keep things simple using either plain javascript or a library like jQuery. I just can't figure out why this code isn't working. Can someone please help me with this issue?