How to get the recordcount of JSON results returned from Coldfusion Component?

1.3k Views Asked by At

I have a Coldfusion Component which returns my search results from a query in JSON using serializeJSON(myquery).

The results returned dont have the ROWCOUNT before the COLUMNS, if i do return the results with the ROWCOUNT then it messes everything up.

What is the best way to display the recordcount without using the ROWCOUNT value?

2

There are 2 best solutions below

1
On BEST ANSWER

Unless there is something you are not telling us, you do not need to include an extra row count. It can be derived from the result.

By default serializeJSON(queryObject) returns a structure with two keys: DATA and COLUMNS (both arrays). DATA represents the rows in the query. So to obtain the query row count, simply check the length of the DATA array.

5
On

If the serialized object is a query object, you should be able to deserialize the JSON and get the array length of records from the result structure's data key.

So,

arrayLen(deserializeJSON(result).data)