If you can't fix the JSON document you can create a custom JSON type converter and apply it to the style
property. And whoever created that document needs to fix their bug.
If you use System.Text.Json, a possible converter could be :
public class StyleStringJsonConverter : JsonConverter<Style>
{
public override Style Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options) =>
JsonSerializer.Deserialize<Style>(reader.GetString()!);
public override void Write(
Utf8JsonWriter writer,
Style style,
JsonSerializerOptions options) =>
writer.WriteStringValue(JsonSerializer.Serialize(style));
}
This can be applied through an attribute :
public class Root
{
public string lng_x { get; set; }
[JsonConverter(typeof(StyleStringJsonConverter))]
public Style style { get; set; }
}
JSON.NET also has custom converters:
public class StyleStringConverter : JsonConverter<Style>
{
public override void WriteJson(JsonWriter writer, Style value, JsonSerializer serializer)
{
writer.WriteValue(JsonConvert.SerializeObject(value));
}
public override Style ReadJson(JsonReader reader, Type objectType, Style existingValue, bool hasExistingValue, JsonSerializer serializer)
{
string s = (string)reader.Value;
return JsonConvert.DeserializeObject<Style>(s);
}
}
This can be applied using an attribute too:
public class Root
{
public string lng_x { get; set; }
[JsonConverter(typeof(StyleStringJsonConverter))]
public Style style { get; set; }
}