package api

import (
        "code.google.com/p/gorest"
	"github.com/matttproud/prometheus/rules"
	"github.com/matttproud/prometheus/rules/ast"
        "time"
)
func (serv MetricsService) Query(Expr string, Json string, Start string, End string) (result string) {
        exprNode, err := rules.LoadExprFromString(Expr)
        if err != nil {
                return err.Error()
        }

        timestamp := time.Now()

        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)
}

package api

import (
	"github.com/matttproud/prometheus/rules"
	"github.com/matttproud/prometheus/rules/ast"
        "time"
)
func (serv MetricsService) Query(Expr string, Json string, Start string, End string) (result string) {
        exprNode, err := rules.LoadExprFromString(Expr)
        if err != nil {
                return err.Error()
        }

        timestamp := time.Now()

        format := ast.TEXT
        if Json != "" {
                format = ast.JSON
        }
        return ast.EvalToString(exprNode, &timestamp, format)
}

--- 
+++ 
@@ -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 @@
 
         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.
