I want to add linebreaks to a JSON file that contains the configuration of a game I'm making. The idea is to have a list that contains stats that can be changed by anybody who wants to. The way I'm doing it right now is to assign a name to the JSON list like so:
configuration = '{"example1": false, "example2": "something"}';
Then, I can access the config file by creating a variable in JS like so:
var config = JSON.parse(configuration);
And then I can set variable's values to a specific object in the JSON file like so:
var sampleVariable = config.example1;
This make "sampleVariable" be equal to "false" because that's how it's set up in the JSON file.
The problem is, I'm forced to keep the file in one line, any break breaks the file and I can't access any of its contents. How can I add breaks to every line in order to keep it human readable? This is what I have in mind:
configuration = '{
"example1": false,
"example2": "something"
}';
EDIT: I tried the supossed "duplicate" question, doesn't work.
You can use template literals as follows (using backticks instead of quotes to delimit the string):
const configuration = `
{
"example1": false,
"example2": "something"
}`;
console.log(JSON.parse(configuration).example2); // "something"
Template literals preserve newline characters.