I am looking for a way to parse a local JSON file from a none-hosted HTML page (e.g.: file:///C:/Folder/To/Your/HTML/default.html
) without using AJAX since it will only entail an allow access-origin
error.
I also cannot use JSONP since the HTML is not hosted to any hosting server (whether locally or remotely hosted).
Asked
Active
Viewed 121 times
0

Jenny Casarino
- 115
- 1
- 4
-
can you use a file input? – dandavis Nov 19 '15 at 06:18
-
3Possible duplicate of [Loading local json file](http://stackoverflow.com/questions/7346563/loading-local-json-file) – IanB Nov 19 '15 at 06:25
-
Maybe you can load it in an iframe using the src attribute and parse the contents using innerHTML. – DDS Nov 19 '15 at 06:35
1 Answers
0
suppose your json file 'json.data' is like below:
data = '[{"name" : "Harry", "age" : "32"}]';
you have to load the json file into html head section like below:
<script type="text/javascript" src="file.json"></script>
and then in body section you have to call the javascript function to parse json data like..
<body onload="load();"></body>
javascript code:
<script>
function load() {
var mydata = JSON.parse(data);
alert(mydata[0].name);
alert(mydata[0].age);
}
</script>
that's it.

user-4653387
- 305
- 1
- 4
- 17
-
you can also see this thread - http://stackoverflow.com/questions/17944344/parse-local-json-file-with-jquery-and-javascript – user-4653387 Nov 19 '15 at 06:32
-