Hello all,
I am making a request to check an API for a particular asset: 157805
How would I count the number of records returned for this JSON array?
Example below: (modified to only show asset data)
- {"result":[{"parent":"", "asset_tag":"157805"},
- {"parent":"","asset_tag":"157805"}]}
My thoughts are that I should be using the Native FileMaker JSON function:
JSONListKeys ( $data ; "result" ) ;
The result is:
0
1
I was able to count these two data points using ValueCount($data)
I just answered my own question - so hopefully this helps someone else! -JF
An important addition to this is WHY it returned 0 & 1 rather than "result" and "parent".
In your example, your data is wrapped by {}, indicating a JSON Object. So your data is an array of two objects.
Since your data was formatted in that way, instead of this "associative" (key => value named) array like this:
when you used the JSONListKeys() function, it treated it as a zero-index array instead. This is why 0 & 1 was returned instead of result & parent.
Just a thought to clarify. It's important to know the difference between objects and arrays, and the fact that they can be nested into each other.