Consider that we have a file called configuration.js, and when we look inside we see:
'use strict';
var profile = {
"project": "%ProjectsRoot%\\SampleProject\\Site\\Site.csproj",
"projectsRootKey": "%ProjectsRoot%",
"ftp": {
"address": "ftp://192.168.40.50/",
"username": "",
"password": ""
},
"delete": [
"\\b(bin)\\b.*\\.config",
"\\b(bin)\\b.*\\.js",
"\\b(bin)\\b.*\\.css",
"bin\\\\(?!ProjectName).*\\.(dll|pdb)"
],
"replace": [
{
"file": "Web.config",
"items": [
{
"regex": "(<appSettings file=\")(bin\\\\)(Settings.config\">)",
"newValue": "$1$3"
},
{
"regex": "<remove\\s*segment=.bin.\\s/>",
"newValue": ""
}
]
}
]
};
In this case, the content of .js file is intended to be only JSON, yet for some IDE reasons it's stated as a JavaScript statement so that IDE recognizes the content and formats it correctly. This file might in another scenario contain:
{
"project": "%ProjectsRoot%\\SampleProject\\Site\\Site.csproj",
"projectsRootKey": "%ProjectsRoot%",
"ftp": {
"address": "ftp://192.168.40.50/",
"username": "",
"password": ""
},
"delete": [
"\\b(bin)\\b.*\\.config",
"\\b(bin)\\b.*\\.js",
"\\b(bin)\\b.*\\.css",
"bin\\\\(?!ProjectName).*\\.(dll|pdb)"
],
"replace": [
{
"file": "Web.config",
"items": [
{
"regex": "(<appSettings file=\")(bin\\\\)(Settings.config\">)",
"newValue": "$1$3"
},
{
"regex": "<remove\\s*segment=.bin.\\s/>",
"newValue": ""
}
]
}
]
}
In both cases, the extension of files are better to be .json, rather than to be .js. We're creating a quality tool that has many features, one of which is to suggest to the developer to change file's extension based on content.
In both cases, how can we make sure that the file only contains JSON, or is INTENDED to only contain JSON?
Note: the reason for complex JSON here as example is to bring forward a real-word sample.
{"...":"..."}excluding spaces, end of lines...intended to be JSON?