Neo
Neo

Reputation: 16239

how to retrieve blob data from Azure blob in Json format?

I have stored json data format in azure blob storage, Now want to retrieve that data from azure blob in the form of json.

I tried like following

 //get all blob from contrainer
            var storageAccount = CloudStorageAccount.Parse("connection string");
            var blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("tablesblob");

            foreach (IListBlobItem item in container.ListBlobs(null, false))
            {
                if (item.GetType() == typeof(CloudBlockBlob))
                {
                    CloudBlockBlob blob = (CloudBlockBlob)item;
                    var ms = new MemoryStream();
                    //blob.DownloadToStream(ms); how to get blob data in the form of JSON?
                }
            }

how to get azure blob data in the form of JSON?

Upvotes: 12

Views: 16453

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136366

You could try CloudBlockBlob.DownloadText method to download the blob contents as text and then use Json.Net's JsonConvert to serialize the string into your customer object. For example, something like the following:

            var customerData = blob.DownloadText();
            var customer = JsonConvert.DeserializeObject<Customer>(customerData);

Upvotes: 16

Related Questions