I am creating a list of objects in C#. I want to save them in proper JSON format on the go in the blob storage container. Currently I am saving them on my local drive and then upload to blob. Two problem I am facing: 1. Json format when I add new objects looks like:
[
{
"id": "1",
"Name": "Peter",
"Surname": "Pan"
}
]
[
{
"id": "2",
"Name": "Steve",
"Surname": "Pan"
}
]
How may I update my code to make them one array with comma separeted values?
[
{
"id": "1",
"Name": "Peter",
"Surname": "Pan"
},
{
"id": "2",
"Name": "Steve",
"Surname": "Pan"
}
]
- Is there a way to save to my blob without first saving the file on my local drive?
List<Obj> list= new List<Obj>();
list.Add(new Obj()
{
Id = "1",
Name = "Peter",
Surname = "Pan"
});
// Serialize to JSON output
var serializer = new JavaScriptSerializer();
var serializedResult = serializer.Serialize(list);
// write string to file locally
System.IO.File.AppendAllText(@"people.json", serializedResult);
//Create or overwrite the "myblob" blob with the contents of a local file
using (var fileStream = System.IO.File.OpenRead(@"people.json"))
{
await blockBlob.UploadFromStreamAsync(fileStream);
}
Json out has wrong format with new object created being a new array also how to upload this file without saving a copy on my local drive?