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


Java Version 22 Released
04/04/2024

JDK 22 is not a Long Term Support release, but is one of the regular releases that are scheduled to arrive every six months. Still, it has got a lot to show for itself.



Microsoft's Cybersecurity For Beginners
30/04/2024

A free, self-paced course about Cybersecurity 101 is on offer by Microsoft's Cloud Security Advocates. It's a 30+ lesson curriculum targeted at complete novices.


More News

raspberry pi books

 

Comments




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