Sundae.js uses a JSON file to control its test cases. I define a rigid API with the expected test case format, and a user fills out a JSON file at least suppling the required field. A sample of my valid JSON file can be found here.
So in order to get a JSON file, or the contents of any file as a string you need to create a XMLHttpRequest() object. The Mozilla MDC provides detailed explanations of its attributes and expected uses and cautions.
Here are the steps I followed to get this done for Sundae.js:
- Make a XMLHttpRequest() object.
- Set its open parameters
- Set its onload()
- Very handy for managing callback functions
- Also handy for using the objects responseText
- Set its send to null
As usual here is a pastebin of getJSON, and there you have it. Alternatively if you aren't using valid JSON for JSON.parse(responseText) of your file, you should use eval("(" + responseText + ")").