'jsondoc.json: Option Public Option Declare Use "WebSession" Dim doc As NotesDocument Dim Db As NotesDatabase Sub Initialize Dim sDbName As String Dim sServer As String Dim iPos As String Print "Content-type: application/json" ' Get the database to open. sDbName = web.getQueryString("db") If sDbName = "" Then Call dspError("Database Required") End End If ' If the database includes a server put the server in a server field. iPos = Instr(sDbName, "!!") If iPos > 0 Then sServer = Left(sDbName, iPos - 1) sDbName = Mid(sDbName, iPos + 2) Else sServer = "" End If ' Open the database. Set db = New NotesDatabase( sServer, sDbName ) If Not db.IsOpen Then If Not db.OpenByReplicaID( sServer, sDbName ) Then If sServer = "" Then Call dspError("Unable to open database: " + sDbName) Else Call dspError("Unable to open database: " + sDbName + " on (" + sServer + ")") End If End End If End If Call getDoc End Sub Sub getDoc Dim doc As NotesDocument Dim sKey As String Dim sFieldName As String Dim sTemp As String Dim sProfile As String Dim aVals As Variant Dim xName As NotesName Dim bFirst As Boolean On Error Resume Next sProfile = web.getQueryString("profile") If sProfile = "" Then ' Use the document's UNID sKey = web.getQueryString("unid") If Len(sKey) = 0 Then Call dspError("UNID is required: " & sKey) Exit Sub End If Set doc = db.GetDocumentByUNID(sKey) If doc Is Nothing Then Call dspError("Unable to open: " & sKey) Exit Sub End If Else Set doc = db.GetProfileDocument(sProfile) If doc Is Nothing Then Call dspError("Unable to open " + sProfile + " profile document") Exit Sub End If End If Print |{| Forall i In doc.Items sFieldName = Replace(Replace(Lcase(i.Name), "$", "dollar_"), " ", "_") If Isarray(i.Values) And Ubound(i.Values) > 0 Then sTemp = "" bFirst = True If i.isNames() Then Forall s In i.Values Set xName = web.session.CreateName(s) If bFirst Then sTemp = sTemp & |"| & web.JSONEncode(xName.Abbreviated) & |"| bFirst = False Else sTemp = sTemp & |,"| & web.JSONEncode(xName.Abbreviated) & |"| End If End Forall Elseif i.type = 1024 Then ' Date/Time element. Forall d In i.Values If bFirst Then sTemp = sTemp & |"| & web.JSONEncode(Cstr(d)) & |"| bFirst = False Else sTemp = sTemp & |,"| & web.JSONEncode(Cstr(d)) & |"| End If End Forall Else Forall s In i.Values If bFirst Then sTemp = sTemp & |"| & web.JSONEncode(s) & |"| bFirst = False Else sTemp = sTemp & |,"| & web.JSONEncode(s) & |"| End If End Forall End If Print |"|; sFieldName; |":[|;sTemp; |],| Elseif i.isNames() Then Set xName = web.session.CreateName(i.Text) Print |"|; sFieldName; |":"|;web.JSONEncode(xName.Abbreviated); |",| Else If Instr(i.Text, Chr$(13) + Chr$(10)) > 0 Then ' Remove carriage returns and leave line feeds in the text. Print |"|; sFieldName; |":"|;web.JSONEncode(Replace(i.Text, Chr$(13) + Chr$(10), Chr$(10))); |",| Elseif i.type = 768 Then ' Number, does not need quotes. Print |"|; sFieldName; |":|;web.JSONEncode(i.Text); |,| Else Print |"|; sFieldName; |":"|;web.JSONEncode(i.Text); |",| End If End If End Forall Print |"unid":"|; doc.UniversalID; |"}| End Sub Sub dspError (sErrText As String) Print |{"error":"| + web.JSONEncode(sErrText) + |"};| End Sub