JSON output

dog can format its output as JSON. If it is being run as part of a script, of if the results are going to be sent to another program, it is preferable to output in a machine-readable language instead of attempting to parse the default output, which is meant to be read by people.

To output as JSON, pass the -J or --json command-line option.

dog example.com A AAAA MX TXT --json

The results will be in a top-level object, and each response will contain the original query, as well as the Answer, Additional, and Authoritative sections.

The JSON produced will be unformatted, with no whitespace or line breaks. To make it more readable for a person, pipe it through a JSON formatter such as jq.

$ dog example.com --json | jq
{
  "responses": [
    {
      "additionals": [],
      "answers": [
        {
          "address": "93.184.216.34",
          "class": "IN",
          "name": "example.com.",
          "ttl": 648,
          "type": "A"
        }
      ],
      "authorities": [],
      "queries": [
        {
          "class": "IN",
          "name": "example.com.",
          "type": 1
        }
      ]
    }
  ]
}