How to send the right script return value so the reformatted JSON appears correctly?

Hello,

I'm having trouble with how my output looks in my data for the script I've created. I've created the script in a way where the output is a String that is precisely aligned to JSON format (using the Newtonsoft.Json.Linq.JObject format). However, I'm using this script mainly from the REST API, which reformats all of its inputs into JSON again. So the output is wrongly formatted.

My script:

#If Not SCRIPTDEBUGGER
References Newtonsoft.Json.dll
#End If
Public Function CCC_return_UID_from_BUN (ByVal Username As String) As String
'Dim person As ISingleDbObject = Connection.CreateSingle("Person", UID_Person)
Dim fName As String = Nothing
Dim lName As String = Nothing
Dim bun As String = Nothing
Dim empNum As String = Nothing
Dim finalObject As String = Nothing
Dim finalBody As Newtonsoft.Json.Linq.JObject = New Newtonsoft.Json.Linq.JObject()
Dim f As ISqlFormatter = Connection.SqlFormatter
Dim collectionPer As IColDbObject = Connection.CreateCol("Person")
Dim requestBody As Newtonsoft.Json.Linq.JObject = New Newtonsoft.Json.Linq.JObject()
Dim counter As Integer = 0
Dim UID_Person = Nothing

UID_Person = CCC_Retrieve_GUID(Username)

collectionPer.Prototype.WhereClause = f.Comparison("uid_personhead", UID_Person, ValType.String, CompareOperator.Equal)

'Mark columns as display columns
collectionPer.Prototype("FirstName").IsDisplayItem = True
collectionPer.Prototype("LastName").IsDisplayItem = True
collectionPer.Prototype("CentralAccount").IsDisplayItem = True
collectionPer.Prototype("PersonnelNumber").IsDisplayItem = True

collectionPer.Load()

If collectionPer.count > 0 Then
For Each colElement As IColElem In collectionPer
counter += 1
requestBody = New Newtonsoft.Json.Linq.JObject
fName = colElement.GetValue("FirstName")
requestBody.Add("FirstName",fName)
lName = colElement.GetValue("LastName")
requestBody.Add("LastName",fName)
bun = colElement.GetValue("CentralAccount")
requestBody.Add("BUN",bun)
empNum = colElement.GetValue("PersonnelNumber")
requestBody.Add("EmployeeNumber",empNum)
'finalObject = finalObject & fName & lName & bun & empNum
finalBody.Add("Person" & counter.ToString, requestBody)
Next
'Return finalBody.toString
Return finalBody.ToString()
Else
'requestBody = New Newtonsoft.Json.Linq.JObject
'requestBody.Add("No Response","No Response")
Return "No reportess"
End If
End Function

Using the input value, I get the output from the script as:

{
"Person1": {
"FirstName": "Name1",
"LastName": "Name1",
"BUN": "Name1",
"EmployeeNumber": "Name1"
},
"Person2": {
"FirstName": "Name22",
"LastName": "Name2",
"BUN": "Nam2",
"EmployeeNumber": "Nam2"
},
"Person3": {
"FirstName": "Name3",
"LastName": "Name3",
"BUN": "ASABOORI",
"EmployeeNumber": "Nam3"
}
}

(pasting the output into here removed the indentations, but they were indented correctly by JSON standards)

But the output of the script, which reformats the JSON format again into another JSON format is:

{
  "result": "{\r\n  \"Person1\": {\r\n    \"FirstName\": \"name1\",\r\n    \"LastName\": \".\",\r\n    \"BUN\": \"name1\",\r\n    \"EmployeeNumber\": \"nam1\"\r\n  },\r\n  \"Person2\": {\r\n    \"FirstName\": \"name2\",\r\n    \"LastName\": \"name2\",\r\n    \"BUN\": \"name2\",\r\n    \"EmployeeNumber\": \"name2\"\r\n  },\r\n  \"Person3\": {\r\n    \"FirstName\": \"nam3\",\r\n    \"LastName\": \"name3\",\r\n    \"BUN\": \"name3\",\r\n    \"EmployeeNumber\": \"name3\"\r\n  }\r\n}"
}


There doesn't seem to be a way to turn off the reformatting of the output to JSON again. What type of output can I give so that the reformatting would make it look like a JSON is supposed to?

Thanks,

-Ali

Parents Reply Children
No Data