We would like to create JSON in the below format. We are able to create the first part of the JSON but we doe not now how to create the part that starts with “Objects”.
Hi Peter, We have created the JOBject and added the properties. But we did not manage toe create the Jarray with the Square Bracket as shown in the JSON. That is the part we are stuck right now.
I find it easiest to use an invoke code. I would use something like below to create a Jarray, create some objects and add to the Jarray as items. Finally add the jarray back into the Jobject you want it to be in (assuming that property is already created)
'Create Jarray
out_FileJarray = New Jarray
'create new jobjects
Dim FileJobject1 As New JObject
Dim FileJobject2 As New JObject
'Add properties to the Jobjects
FileJobject1.Add(New JProperty("filePath","file path1"))
FileJobject1.Add(New JProperty("name","file name1"))
FileJobject2.Add(New JProperty("filePath","file path2"))
FileJobject2.Add(New JProperty("name","file name2"))
'Add objects to array
out_FileJarray.Add(FileJobject1)
out_FileJarray.Add(FileJobject2)
'Add Jarray back into the original Jobject
OriginalJObject.Item("ArrayProperty") =DirectCast(out_FileJarray,JToken)