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


Pg_lakehouse Makes PostgreSQL Quack
08/07/2024

Pg_Lakehouse from ParadeDB is an extension that turns PostgreSQL into the analytical engine of DuckDB. Why is that useful? How do you use it?



BusyBeaver(5) Is 47,176,870
03/07/2024

The thing about the BusyBeaver function is that it is very easy to understand, but very difficult to compute. We now know its value up to 5, which isn't much progress for more than 50 years work.


More News

kotlin book

 

Comments




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