$ dig example.com | txr dig.txr
[{"query_time":"1","rcvd":"56","answer_num":1,"status":"NOERROR",
"when_epoch":1702030676,"opcode":"QUERY","udp":"65494","opt_pseudosection":{"edns":{"udp":65494,"flags":[],"version":"0"}},
"query_num":1,"question":{"name":"example.com.","type":"A","class":"IN"},
"server":"127.0.0.53#53(127.0.0.53)","id":"48295","authority_num":0,
"answer":[{"name":"example.com.","type":"A","data":"93.184.216.34","ttl":"4441",
"class":"IN"}],
"additional_num":1,"when":"Fri Dec 08 10:17:56 PST 2023"}]
$ cat dig.txr
@(bind sep @#/[\s\t]+/)
@(skip)
;; ->>HEADER<<- opcode: @opcode, status: @status, id: @id
;; flags: qr rd ra; QUERY: @query, ANSWER: @answer, AUTHORITY: @auth, ADDITIONAL: @additional
@(skip)
;; OPT PSEUDOSECTION:
; EDNS: version: @edns_ver, flags:@flags; udp: @udp
@(skip)
;; QUESTION SECTION:
;@qname@sep@qclass@sep@qtype
@(skip)
;; ANSWER SECTION:
@aname@sep@ttl@sep@aclass@sep@atype@sep@data
;; Query time: @qtime msec
;; SERVER: @server
;; WHEN: @when
;; MSG SIZE rcvd: @rcvd
@(do (put-jsonl #J^[{
"id" : ~id,
"opcode" : ~opcode,
"status" : ~status,
"udp" : ~udp,
"query_num" : ~(tofloat query),
"answer_num" : ~(tofloat answer),
"authority_num" : ~(tofloat auth),
"additional_num" : ~(tofloat additional),
"opt_pseudosection" :
{
"edns" :
{
"version" : ~edns_ver,
"flags" : [],
"udp" : ~(tofloat udp)
}
},
"question" :
{
"name" : ~qname,
"class" : ~qclass,
"type" : ~qtype
},
"answer" :
[
{
"name" : ~aname,
"class" : ~aclass,
"type" : ~atype,
"ttl" : ~ttl,
"data" : ~data
}
],
"query_time" : ~qtime,
"server" : ~server,
"rcvd" : ~rcvd,
"when" : ~when,
"when_epoch" : ~(time-parse "%a %b %d %T %Z %Y" when).(time-utc)
}]))
The latest TXR (292 as of time of writing) allows integers in JSON data, so (toint query) could be used.