Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A tidy solution for using static JSON data

I'm developing a simple JavaScript (jQuery) slide show. I wanted to use JSON to store some some static parameters about the content of each slide.

Since I like to keep my data separate from my code, is there anyway to have JavaScript evaluate a .json file?

  • AJAX seems a bit overkill - it just needs to evaluate it at run-time, nothing is dynamic.
  • I could have a separate .js file that holds my JSON data as an object - but this seems messy.

So before I use one of the above solutions, I just wanted to make sure there wasn't a cleaner way to have JavaScript evaluate a text file.

like image 936
KeyboardInterrupt Avatar asked Nov 30 '09 20:11

KeyboardInterrupt


People also ask

What is static JSON?

json-static is a tool for converting parsed JSON data with an unchecked structure into specialized OCaml types and vice-versa. It is a complement to the json-wheel library which provides a parser and a (pretty-) printer.

What is toJSON () in JSON?

toJSON() calls the object's toISOString() method, which returns a string representing the Date object's value. This method is generally intended to, by default, usefully serialize Date objects during JSON serialization, which can then be deserialized using the Date() constructor or Date. parse() as the reviver of JSON.


1 Answers

What's wrong with having a separate js file for your object? It has to live somewhere. I agree ajax is overkill, but I'm at a loss for why you think a JavaScript object in a .js file is "messy."

like image 132
Nosredna Avatar answered Sep 24 '22 23:09

Nosredna