Access/VBA Library

QueryToJSON

Returns a String containing a JSON representation of all of the result of a query.

Syntax

QueryToJSON( query )
Parameters
Name Type Description
query String Required. A valid SQL SELECT-statement or tablename.
Return value

String : JSON representation of all records returned by the query . It will be an Array and each record in the Array will be represented as an object.

Code
Function QueryToJSON(query As String) As String
    QueryToJSON = CollectionToJSON(QueryRows(query))
End Function

JSONtag:JSONDatabasetag:DatabaseSQLtag:SQL

See also

  • CollectionToJSON
  • QueryRows
Example
' The results of these two statements are the same
Debug.Print QueryToJSON( "SELECT * FROM employee" )
Debug.Print QueryToJSON( "employee" )