I have read a file with a JSON appearance, and the format is similar to the following:
{
varParent1: {
var1: true,
var2: "this is a string",
var3: 0,
var4: "another string"
},
varParent2:{
var1: false,
var2: 0,
var3: 92,
var4: "string here",
var5: "string2 here"
}
}
I have this code in a variable, but I can't edit the file, so I should work only with the variable.
As everybody can see, it is not a valid format JSON, so I am not being able to parse it. I need to format it to something like this:
{
"varParent1": {
"var1": true,
"var2": "this is a string",
"var3": 0,
"var4": "another string"
},
"varParent2":{
"var1": false,
"var2": 0,
"var3": 92,
"var4": "string here",
"var5": "string2 here"
}
}
I have thought about the logic and I have a conclusion (I think it's fine): I have to add '"' to the start and end of every line and between ":" too. But i'm not able to do that with regex.
Is there an easier way?