JSON Serialization and deserialization

JSON Serialization and deserialization

  Note

The JSON serialization will be done according to RFC 8427.

On Deserialization it is not guaranteed which value will be used, if there are non-matching attributes for the same field in the dns message are used (e.g. "QTYPE":"1","QTYPEname":"MX").

The raw octet properties defined in Secion 2.4 of RFC 8427 are not supported.

JSON Serialization/Deserialization

C#
// Serialize
var message = new DnsMessage()
{
    // ...
};
var json = System.Text.Json.JsonSerializer.Serialize(message, new JsonSerializerOptions() { WriteIndented = true });

// Deserialize
var msg2 = System.Text.Json.JsonSerializer.Deserialize<DnsMessage>(json);