0

I will like to read a JSON file (kind of like a webservice running on a server) and process it using JavaScript.

I was wondering if anyone will be able to point me to some good example, tutorials or sample code?

Much appreciated.

4
  • 1
    google has some good examples. what have you tried? has it worked? Commented Nov 11, 2012 at 4:23
  • What exactly are you having problems with? Commented Nov 11, 2012 at 4:23
  • The answers I found on Google all lead to parsing a JSON string in a var. But what if my var is a URI? Eg. var JSON_URL = "abc.com/data.json" Commented Nov 11, 2012 at 4:26
  • 3
    This are two independent problems: Getting the data and parsing it. You have to Ajax to load the JSON file. If file is from an external domain, you have to use a proxy or JSONP if supported by the server (but that's not JSON anymore, despite its name). Commented Nov 11, 2012 at 4:27

2 Answers 2

1

You can use jQuery's $.getJSON function. See the jQuery documentation

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

Comments

0

I'm not sure if I understand your question entirely, but if you have a string accessible in your JS, you can call JSON.parse(yourString) which will return a JS object representation of the string. This should work in all modern browsers.

2 Comments

Nope. I am looking to do a JSON.parse(URI). Eg. var JSON_URL = "abc.com/data.json"
Ah, gotcha. In this case, you can do as Felix commented above on your initial question -- make an AJAX request to your server, read the text response and then call JSON.parse. If this is not your server, then you may have cross-domain issues -- can you clarify your use case a little bit more?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.