Is there a way to convert certain parts of a JSON string into booleans?
Here is an example of my JSON string:
{
"file_id": {
"width": "560",
"height": "270",
"esc_button": "1",
"overlay_close": "1",
"overlay_opacity": "1"
}
}
If this were my personal project, I would prefer to convert booleans into true/false
strings rather than keeping them as 1 and 0
. Since it's not my personal project, I am wondering if there is a way to specify which properties in the JSON string should be treated as booleans. In this example, the booleans would be: esc_button, overlay_close
, but not overlay_opacity
...
Since this is a JavaScript project, I am curious about what options are available to me and if there is an easy way to achieve this? There are additional settings in this JSON string, but I have only shared a portion of it. The settings vary based on click events
(different file_id === different settings)
EDIT:
I just realized that I could use
parseInt(settings[file_id].esc_button)
to obtain a boolean value, but do I really need to use this method every time? Are there other techniques that I may be unaware of?