Problem with Parsing?

Options

Here is what the JSON looks like:

This first screenshot parses correctly

This second screenshot gives me this error:

Exception: Unable to locate var: all_data.totals.statistics.pitching

Why is this behaving as such? It makes no logical sense to me.

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hi @rlove both screenshots are the same, is this intentional?

    The unable to locate var error happens when the variable is not found at this path. This can often happen when working with external data because not every response is the same. The quick solution is to use the GET filter instead of dot notation so that you can define a default value when the hard-coded path on the variable does no exist.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Hi @rlove, Michael's comment will stop the error, but it looks from your message that the pitching should be in the all_data set. If that's the case (e.g. we are iterating over National League pitchers) maybe you could show what Xano sees right before that line, either from the debugger or by adding a stop-and-debug that displays all_data?

    A possible situation is that this is inside an array, and all_data is gathered within the array loop. If you were looping over the players of a baseball team, you might find that they all have hitting stats, but only pitchers have pitching stats. So the "all_data" for the pitcher would have both hitting and pitching, but for the first baseman, there would only be hitting. In that case, you would want either to use the get filter like Michael describes or handle the difference in stats for a given position with more nuanced business logic.