During my project, I have transitioned from using XML format to JSON format. The XML structure includes nodes such as:
<Creature>
<Name>Someone</Name>
<Desert>false</Desert>
<Woods>false</Woods>
<Mountains>false</Mountains>
<Swamp>false</Swamp>
</Creature>
Accompanied by a radio button list with values matching the tag names. For example:
<input type="radio" name="creature_terrain" value="Desert" />Desert<br>
In the old code, filtering the XML list was achieved through the following method:
let selector = 'Creature > ' + selectedTerrain + ':contains("true")';
var filteredCreatures = $(creaturesArray).find(selector).parent();
Now that I am working with a JSON array like:
{
"Name": "Someone",
"Desert": false,
"Woods": false,
"Mountains": false,
"Swamp": false
}
I am struggling to find an elegant way to filter it compared to how it was done with XML. The only solution I can think of is utilizing switch/case statements. Any other suggestions?