Question

So, I'm trying to create some helpful JSON files that other can use to prototype out applications using State JSON data with image names that correspond to actual images I have in the same directory.

Here are my files : https://github.com/tannerjt/state_images.json

My question is this... since JSON is just javascript, should I use .json or .js for files.

One of my files is technically JSON, but I named it states.js, since it is an array of javascript object...

[
  {
    "name": "Alabama",
    "abbreviation": "AL",
    "capital": "",
    "image": {
      "image_name": "alabama.jpg",
      "location": "Monte Sano State Park",
      "credit": {
        "author": "Wes Thomas (BamaWester on Flickr)",
        "url": "http://www.flickr.com/photos/bamawester/3493269235/"
      }
    }
  },....
]

Because I called it a .js file, I added

var states = [{...

to the beginning. With it being an Array of json object... JSONlint still validated it.

Any thoughts? I want to make this useful for people to play around with, but not sure how I name the files correctly.

Was it helpful?

Solution

if you included var states = [{... in your raw text and tried to parse the thing as a json object, it would probably fail. Saving it as a .json file and leaving it only with data would be a preferred option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top