/// <summary> /// Converts the json value represented by <see cref="BinaryData"/> to an object of a specific type. /// </summary> /// <param name="data">The <see cref="BinaryData"/> instance to convert.</param> /// <returns> The object value of the json value. /// If the object contains a primitive type such as string, int, double, bool, or null literal, it returns that type. /// Otherwise, it returns either an object[] or Dictionary<string, object>. /// Each value in the key value pair or list will also be converted into a primitive or another complex type recursively. /// </returns> public static object?ToObjectFromJson(this BinaryData data) { JsonElement element = data.ToObjectFromJson <JsonElement>(); return(element.GetObject()); }
/// <summary> /// Converts the <see cref="BinaryData"/> to a Dictionary of string to object. /// Each value in the key value pair will be strongly typed as an int, long, string, Guid, double or bool. /// Each value can also be another Dictionary of string object representing an inner object or /// a List of objects representing an array. /// </summary> /// <param name="data">The <see cref="BinaryData"/> instance to convert.</param> /// <returns>The data converted to the Dictionary of string to object.</returns> public static IDictionary <string, object?> ToDictionaryFromJson(this BinaryData data) { JsonElement element = data.ToObjectFromJson <JsonElement>(); return(element.GetObject() as Dictionary <string, object?> ?? throw new InvalidOperationException("The BinaryData instance did not represent a JSON object so it cannot be converted into a dictionary.")); }