One of simple approaches is shown in the next example:
class MyData
{
[JsonIgnore]
public bool is_admin { get; set; }
[EditorBrowsable( EditorBrowsableState.Never )]
[JsonPropertyName( "is_admin" )]
public int is_admin_as_int
{
get
{
return is_admin ? 1 : 0;
}
set
{
is_admin = value != 0;
}
}
public string mobile { get; set; }
}
// sample usage:
var data = new MyData { is_admin = true, mobile = "026547388" };
string json = JsonSerializer.Serialize( data ); // {"is_admin":1,"mobile":"026547388"}
MyData data2 = JsonSerializer.Deserialize<MyData>( json );
See also the topics related to converters, for example: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-converters-how-to.