   [json]
   (if (nil? json)
     []
-    ["-d" json]))
+    ["-d" (generate-string json {:pretty true})]))
 
 (defn- command
   "Build docker command"

        (into ppayload)
        (into pcommand))))

(defn- parse-payload
  [response]
  (if (= (count response) 1)
    nil
    (parse-string (first response) true)))

(defn- parse-http-code
  [response]
  (if (= (count response) 1)
    (Integer. (first response))
    (Integer. (second response))))

(defn- execute
  "Execute docker command and parse result"
  [method uri headers payload]
  (let [cmd (command method uri headers payload)
        result (apply shell/sh cmd)]
    (if (= 0 (:exit result))
      (let [response (string/split (:out result) #"\n")
            payload (parse-payload response)
            http-code (parse-http-code response)]
        (if (> 400 http-code)
          payload
          (throw (ex-info "Docker engine error!"
                          (assoc payload :code http-code)))))
      (throw (ex-info "Docker client failure!"
                      (parse-string (:err result) true))))))

(defn get
  ([uri] (execute "GET" uri nil nil))

  (:refer-clojure :exclude [get])
  (:require [clojure.java.shell :as shell]
            [clojure.string :as string]
            [cheshire.core :refer [parse-string generate-string]]))

(def ^:private api-version "v1.24")
(def ^:private base-cmd ["curl" "--unix-socket" "/var/run/docker.sock" "-w" "%{http_code}"])
