Attempting to parse a JSON and the endpoint is .text. If I hard code the iteration [0],[1], etc; it will parse correctly. However, I need to capture the last data point.
My thought was to define x as data.events.id.size() which is pulls the correct integer count...
....but when I try to parse data.events[x].text it tries to convert data.events[x] to a string using the function .text (which results in a null error).
Without seeing the actual error or more of the code that got you there, it's hard to say, but my best guess is that this is not really what's happening. You are probably getting an error like this:
java.lang.NullPointerException: Cannot get property 'text' on null object
This means that you are trying to access the .textproperty (not a method call, though in Groovy .getText() is also technically magically there for you whether it was really written or not) on an object that is null. It is null because you are trying to access the index equaling data.events.id.size(), which does not exist. That's because size() returns the actual (human-friendly) number, which for your example is 3. Indexes in Groovy (and most programming languages), however, start at 0. So you really want to use x-1 rather than x in your example.
As a side note, you don't even need to fetch the size; Groovy adds a last() method to iterable objects like this, or you could use negative indices to count from the end. So, either of these would be a less verbose, equivalent way to get the same result:
data.events.last().text
or
data.events[-1].text
However, you may still want to do it like you are (with this change) since it provides an easy way to perform a sanity check on the data (both of the above will fail if the list is empty unless you add additional safeguards). But if it's not a huge deal for your use case, Hubitat will also spit any errors from this to the logs itself.