           returned = "\(error!.localizedDescription)"
         }
         if result != nil {
-          returned = "\(result!)"
+          let type = type(of:result!)
+          self.log("\(type): \(result!)")
+          let is_json = JSONSerialization.isValidJSONObject(result!)
+          if is_json {
+            do {
+              let json = try JSONSerialization.data(withJSONObject: result!)
+              returned = String(data: json, encoding:.utf8)!
+            } catch {
+            }
+          }
+          if returned.characters.count == 0 {
+            returned = "\(result!)"
+          }
         }
         self.sendMessage(id:id, message:ok, data:returned)
       }

      }
      var msg = message
      var rawData = data
      if data.range(of: "\t") != nil {
        msg += ":encoded"
        rawData = rawData.base64Encoded()!
      }
      str += msg

    }
    var msg = message
    var rawData = data
    if data.range(of: "\t") != nil || data.range(of: "\n") != nil {
      msg += "!encoded"
      rawData = rawData.base64Encoded()!
    }
    str += msg
