Announcing dynamic JSON in the Azure Core library for .NET
- Dynamic JSON is now available in the Azure Core library for .NET, allowing you to write code at the protocol layer with a similar look and feel to code written using a client's convenience layer.
- The new feature returns an instance of a type called DynamicJsonObject, which allows you to treat JSON content as a strongly typed model.
- This feature makes it easier to modify JSON content directly, for example, changing the color of a configuration setting.
- The DynamicJsonObject class handles camel-case property names by allowing you to pass a parameter specifying the JSON property naming convention.
- The goal is to make it possible to use syntax similar to Azure SDK client convenience methods, making it easier to transition from using raw JSON to using model-based APIs.
- The DynamicJsonObject class mimics Azure SDK model types, enabling you to access properties using C#-style conventions and check if optional properties have values.
- Setting values on a DynamicJsonObject instance adds the value to a list of changes, similar to how Azure model types handle property values.
- It's important to note that making many changes to a DynamicJsonObject instance may impact performance.
- You can use the Dynamic View feature, along with the REST API documentation for the service you're working with, to understand the available properties in the JSON content.
- If needed, you can bypass property name transformations by using property indexers.
- DynamicJsonObject can be cast to any .NET type as long as the JSON can be deserialized to that type using defaults.