Sub MapToJSON(sm As Map, bEnclose As Boolean) As String
' convert a map to a json string and specify if you want the
' returned string enclosed, the default behavour is true
' clean the map values and ensure there is no quoted values or keys
Dim mout As Map
mout.Initialize
For Each mKey As String In sm.Keys
' get value for each key
Dim mValue As String = sm.Get(mKey)
mValue = mValue.Replace(QUOTE, "")
mKey = mKey.Replace(QUOTE,"")
mout.Put(mKey, mValue)
Next
' convert map to list
Dim values As List = Array(mout)
Dim jsonG As JSONGenerator
' pass list to json generator
jsonG.Initialize2(values)
Dim output As String = jsonG.ToString
If bEnclose = True Then
Return output
Else
output = output.Replace("[{","")
output = output.Replace("}]","")
Return output
End If
End Sub