https://github.com/linkdata/dnsjson
https://github.com/linkdata/dnsjson
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/linkdata/dnsjson
- Owner: linkdata
- License: mit
- Created: 2025-09-18T08:29:35.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-09-18T11:33:17.000Z (6 months ago)
- Last Synced: 2025-09-18T11:34:07.578Z (6 months ago)
- Language: Go
- Size: 51.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/linkdata/dnsjson/actions/workflows/build.yml)
[](https://htmlpreview.github.io/?https://github.com/linkdata/dnsjson/blob/coverage/main/report.html)
[](https://goreportcard.com/report/github.com/linkdata/dnsjson)
[](https://godoc.org/github.com/linkdata/dnsjson)
# dnsjson
JSON (un)marshalling for https://github.com/miekg/dns
This is not [RFC 8427](https://www.rfc-editor.org/rfc/rfc8427.html), rather it is a structured human-readable format.
```go
package main
import (
"encoding/json"
"fmt"
"github.com/linkdata/dnsjson"
"github.com/miekg/dns"
)
func main() {
msg := new(dns.Msg)
msg.SetQuestion("example.com.", dns.TypeA)
msg.Id = 1234
jbytes, err := json.MarshalIndent((*dnsjson.Msg)(msg), "", " ")
if err == nil {
fmt.Println(string(jbytes))
var msg2 dnsjson.Msg
if err = json.Unmarshal(jbytes, &msg2); err == nil {
fmt.Println(dns.Msg(msg2).Question[0].Name)
}
}
if err != nil {
fmt.Println(err)
}
// Output:
// {
// "id": 1234,
// "msgHdr": {
// "opcode": "QUERY",
// "rd": true,
// "rcode": "NOERROR"
// },
// "question": [
// {
// "name": "example.com.",
// "qtype": "A",
// "qclass": "IN"
// }
// ]
// }
// example.com.
}
```