Initially, I transformed a Plist file (XML formatted) into JSON using an online tool. Extracting the important data from this extensive JSON file was not a challenge. Utilizing this crucial data, I am reconstructing a new JSON file that is concise and contains relevant information for a plugin I plan to develop in the future.
The conversion from plist to JSON results in some messy formatting. For instance, <true/>
and <false/>
get converted to JSON as "false":"",
or "true":"",
.
I am utilizing jQuery
For an example, refer to this JSfiddle: jsfiddle example
Or view it here:
// Simplified (not really a JSON file, but this will do it for explaining)
var themeJSON = {
"item": {
"false": "",
},
};
// Determining if it's enabled ("true") or disabled ("false")
// Function for checking if this is the default option
function checkDefault() {
// "true" is a keyword!
if (themeJSON.item.true) {
return "1";
// "false" is also a keyword!
} else(themeJSON.item.false) {
return "0";
}
}
Perhaps I could use another function like find()?
Updated response: Thanks to the suggestions in the comments, here is my updated code:
function checkDefault() {
if (item.hasOwnProperty("true")) {
return "1";
} else if(item.hasOwnProperty("false")) {
return "0";
}
}