diff --git a/api/query.go b/api/query.go
index <HASH>..<HASH> 100644
--- a/api/query.go
+++ b/api/query.go
@@ -1,6 +1,7 @@
 package api
 
 import (
+        "code.google.com/p/gorest"
 	"github.com/matttproud/prometheus/rules"
 	"github.com/matttproud/prometheus/rules/ast"
         "time"
@@ -13,9 +14,15 @@ func (serv MetricsService) Query(Expr string, Json string, Start string, End str
 
         timestamp := time.Now()
 
-        format := ast.TEXT
+        rb := serv.ResponseBuilder()
+        var format ast.OutputFormat
         if Json != "" {
                 format = ast.JSON
+                rb.SetContentType(gorest.Application_Json)
+        } else {
+                format = ast.TEXT
+                rb.SetContentType(gorest.Text_Plain)
         }
+
         return ast.EvalToString(exprNode, &timestamp, format)
 }
Set correct Content-Type header based on output format.