Are .txt files and .json files equally good for storing javascript objects?

javascript, json, jsonp

Solution

Can I simply change the extension of a .json file to .txt without problems?

Yes.

Think about it; the sole purpose of file extensions is to let a file browser (Windows Explorer, Finder Windows) choose a program to open that file with.

By default, `.html` files are opened (for me) with chrome, and chrome does a great job of displaying it as a web page - but, if I renamed the extension `.42ftw`, the data within the file wouldn't change, and I could still render it as html using chromium if I wanted - it's just my File Browser wouldn't know what to do with it.

So, basically, file extensions don't change the within data.

So, as long as you handle the data within your `.txt` files as you did with your `.json` files, you should see no difference. Maybe external packages you use might be configured to load only `.json`, but that shouldn't be a problem.

Problem

Can I simply change the extension of a .json file to .txt without problems? My CMS' file permissions lock access to files with the .json extension. These permissions can't be changed right now. To get around this and still use javascript objects I've changed the extensions of my .json files to .txt. So far so good. Is this a reasonable solution or should I be worried about some unknown catastrophe in the future? - In the past I've also been able to load cross-domain .txt files using JSONP so I thought these two file formats might be fairly similar in storing js objects.

Original source