Microsoft Adds Dynamic JSON To Azure Core Library For .NET
Written by Kay Ewbank   
Tuesday, 11 July 2023

Microsoft has added a  new dynamic type to Azure.Core that lets you treat raw JSON like a strongly typed model.

The Azure SDK team says that they are adding protocol methods to Azure SDK client libraries. These are service methods that return a raw Response instead of the typical strongly typed model contained in Response. When calling these methods, it is possible to parse the response content using any JSON parser, such as JsonDocument.

azure

The team says they know that use of existing APIs can result in code that's difficult to read and that may not cleanly express your intent. To solve this problem, the latest release of Azure.Core introduces a way to get response content as a dynamic type. This feature lets you write code at the protocol layer that has the same look and feel as the code you write using a client's convenience layer.

The Content property on Response is a BinaryData type, which has been extended with a new extension method called ToDynamicFromJson. This method returns an instance of a new type called DynamicData that lets you treat JSON content like a strongly typed model. The dynamic JSON that is returned is also mutable, meaning you can modify its properties or even add new properties to it.

The raw response doesn't look the way a model type would look because .NET types don't use camel-case property names, but Microsoft has a "ToDynamicFromJson" method that can be used to make it look more correct. You can pass a propertyNameFormat parameter to the method, telling it what naming convention your JSON property names use. DynamicData will then convert your C# property names to names that match the JSON content. The developers say this is part of a larger design goal they have for the type, which was for it to behave like an Azure SDK model type.

azure

More Information

Getting Started With Azure SDK Documentation

Related Articles

Microsoft Adds New Azure SDKs

.NET 8 Preview 3 Improves ASP.NET Core

Microsoft Launches Azure Blockchain Service

Azure Functions 2 Supports More Platforms

Go SDK For Azure Released

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Conference Times Ahead
29/03/2024

Following a well-established pattern both Google's and Microsoft's Developer Conferences will take place in May while Apple follows on in June. Here are the dates plus what to expect.



VLOGGER - AI Does Talking Heads
24/03/2024

Developed by Google researchers VLOGGER AI is a system that can create realistic videos of people talking and moving from a single still image and an audio clip as input. 


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info