1. 2

this version just runs a string query and parses the output to EDN

(require '[clojure.java.shell :refer [sh]]
         '[cheshire.core :as json])

(defn osquery [query]
  (let [{:keys [exit out err]} (sh "osqueryi" "--json" query)]
    (if (zero? exit)
      (json/decode out true)
      (throw (Exception. err)))))

(osquery "select * from routes where destination = '::1'")

=> ({:hopcount "0",
     :interface "lo0",
     :mtu "16384",
     :type "local",
     :source "",
     :gateway "::1",
     :netmask "128",
     :flags "2098181",
     :destination "::1",
     :metric "0"})

using honeysql we can make structured queries as well

(require '[clojure.java.shell :refer [sh]]
         '[cheshire.core :as json]
         '[babashka.deps :as deps])

(deps/add-deps '{:deps {com.github.seancorfield/honeysql {:mvn/version "2.2.861"}}})

(require '[honey.sql :as hsql])

(defn osquery [query]
  (let [{:keys [exit out err]} (apply sh "osqueryi" "--json" (hsql/format query {:inline true}))]
    (if (zero? exit)
      (json/decode out true)
      (throw (Exception. err)))))

(osquery {:select [:*] :from [:routes] :where [:= :destination "::1"]})

=> ({:hopcount "0",
     :interface "lo0",
     :mtu "16384",
     :type "local",
     :source "",
     :gateway "::1",
     :netmask "128",
     :flags "2098181",
     :destination "::1",
     :metric "0"})
  1.