1

I am looking for a way to upload a JSON file directly to my Azure Cosmos DB container. I am aware of the "classic" way doing it like:

  • load the JSON file
  • convert it via JsonConvert.DeserializeObject<List<Item>>(data);
  • upload it like "container.CreateItemAsync(item)"

I would like to skip the part where I have to deserialize the JSON and convert it into a C# object.

Is there a method or way like this?

container.CreateItemAsync(myData.json)
4
  • It should be possible but depends on the SDK version are you using. Tell use the name of the nuget package you installed into your project, please. Commented Sep 21, 2022 at 13:58
  • I.e. is it Microsoft.Azure.DocumentDB (old) or Microsoft.Azure.Cosmos (new)? Commented Sep 21, 2022 at 13:59
  • 2
    How about container.CreateItemStreamAsync(): learn.microsoft.com/en-us/dotnet/api/… Commented Sep 21, 2022 at 14:03
  • Have you tried CreateItemAsync<JObject>(). I don't think you can pass the JSON string directly, but a parsed JSON should work. Commented Sep 21, 2022 at 14:03

1 Answer 1

3

With the Cosmos DB SQL API v3 .NET SDK, there is a stream option which will allow already serialized payloads to be passed in container.CreateItemStreamAsync()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.