3

I want to read a JSON file that in my local machinge using Javescript, and parse it to a Javascript object such as this code:

var parsed = JSON.parse(JSON_file);

Is it possible to read the file from the disk? Or there is other methods to do that. Thanks.

5
  • 2
    your question is not actually clear. What is your question? you need to parse JSON in javascript or you need to read file from disk by javascript? Commented Oct 20, 2013 at 19:00
  • 1
    I want to read a JSON file from disk by javascript Commented Oct 20, 2013 at 19:03
  • this has XY problem written all over it: meta.stackexchange.com/questions/66377/what-is-the-xy-problem Commented Oct 20, 2013 at 19:04
  • I think this post will help you much stackoverflow.com/questions/585234/… Commented Oct 20, 2013 at 19:06
  • Are you asking how to read a file, or how to use JSON object? In modern browsers there's FileReader Api available, in older IE's you can use some activeX to read a file (if this is not a web page), just notice, that JSON is supported starting from IE8 on... Commented Oct 20, 2013 at 19:09

1 Answer 1

3

Here is a nice tutorial on how you can do it using HTML5's FileReader API, but there is one constraint: you can only interact with a file selected by the user via a file input field.

http://www.html5rocks.com/en/tutorials/file/dndfiles/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.