Access/VBA Library

CollectionToJSON

Returns a String containing a JSON representation of a Collection.

Syntax

CollectionToJSON( Data )
Parameters
Name Type Description
Data Collection Required. Data to be converted to JSON.
Return value

String : JSON representation of the Collection data.

Code
Public Function CollectionToJSON(Data As Collection) As String
    Dim pfx As String
    Dim i As Long
    Dim js As String
    
    js = "["
    
    For i = 1 To Data.Count
        Concat js, pfx, JSONvalue(Data(i))
        pfx = ","
    Next i
    Concat js, "]"
    
    CollectionToJSON = js
End Function

JSONtag:JSONCollectiontag:Collection

Remarks

  • The JSON layout of a Collection is the same as for an Array.

See also

  • JSONvalue
  • Concat