I'm trying to create this JSON below using JSON.Net but i received an error of
Can not add Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JArray
I was able to get the output up until "cpu" but i can't create "disks" which involves array.
JSON I'm trying to make:
{
"spec":{
"name":"SampleVM",
"cpu":{
"hot_remove_enabled":true,
"count":1,
"hot_add_enabled":true,
"cores_per_socket":1
},
"disks":[
{
"new_vmdk":{
"capacity":1024
}
}
]
}
}
My code
JObject newjson =
new JObject(
new JProperty("spec",
new JProperty("name","SampleVM"),
new JProperty("cpu",new JObject
{
new JProperty("hot_remove_enabled",true),
new JProperty("count",1),
new JProperty("hot_add_enabled",true),
new JProperty("cores_per_socket",1)
}),
new JProperty("disks", new JArray(
new JObject
{
new JProperty("new_vmdk",new JObject{
new JProperty("capacity",1024)
})
}
))));
What can i change in my code to get the exact same output as the JSON? My problem mainly lies on trying to recreate "disks" JProperty which has array.