Forum Discussion

marting's avatar
marting
Icon for Neophyte rankNeophyte
2 years ago

JSON Path capability in a Webpage DataSource

I think the answer to this is gonna be “You need to script it, dummy”, but figured I’d check anyway... I'm working on a new DataSource that pulls/interprets JSON data from a peudo-custom system via ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    There’s an easier way than this:

    function parseBooleanValue(value) {
    if (value === 'true') {
    return 1;
    } else if (value === 'false') {
    return 0;
    } else {
    return null; // or throw an error, depending on how you want to handle invalid values
    }
    }

    It uses the ternary operator:

    (value == "true") ? 1 : 0

    This is exactly equivalent to:

    if (value == "true") {
    return 1
    } else {
    return 0
    }

    No need for a function at all, it’s overkill.