0

We are building a static app of sorts where a user can publish static pages from our site, download them and install them on their own web server. In order to do this we are relying on JSON data which will be stored in json files. My concern is that we have no way of controlling their servers and I am unclear if their servers will support .json file mime/types.

Can we just save the json data in a .js file, instead to avoid this potential problem?

6
  • Yes why not? JSON is a part of JavaScript Jun 20, 2014 at 14:06
  • @Hanky웃Panky: Eh, no. JSON is a object notation based on JavaScript.
    – Cerbrus
    Jun 20, 2014 at 14:06
  • That makes the notation valid enough to be placed in a .js file :) Jun 20, 2014 at 14:11
  • That's true, indeed. I'm just nitpicking ;-)
    – Cerbrus
    Jun 20, 2014 at 14:14
  • 1
    @Cerbrus I read nitpicking and had to step in. JSON is not 100% compatible with JavaScript timelessrepo.com/json-isnt-a-javascript-subset
    – Prinzhorn
    Jun 20, 2014 at 14:24

1 Answer 1

1

Sure. Just save it as a variable in JS.

var myJsonData = {
    "thing": true,
    "otherThing:" 4
    "fancyArray":[
        "hello",
        "hi",
        "greetings"
    ]
};
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.