Commit f62eb28f by Marcus Efraimsson Committed by GitHub

Datasource: Use json-iterator configuration compatible with standard library (#30732)

This will make sure that any map keys in JSON is ordered in /api/ds/query response.
parent 9407cdd5
...@@ -102,7 +102,12 @@ func (r StreamingResponse) WriteTo(ctx *models.ReqContext) { ...@@ -102,7 +102,12 @@ func (r StreamingResponse) WriteTo(ctx *models.ReqContext) {
header[k] = v header[k] = v
} }
ctx.Resp.WriteHeader(r.status) ctx.Resp.WriteHeader(r.status)
enc := jsoniter.NewEncoder(ctx.Resp)
// Use a configuration that's compatible with the standard library
// to minimize the risk of introducing bugs. This will make sure
// that map keys is ordered.
jsonCfg := jsoniter.ConfigCompatibleWithStandardLibrary
enc := jsonCfg.NewEncoder(ctx.Resp)
if err := enc.Encode(r.body); err != nil { if err := enc.Encode(r.body); err != nil {
ctx.Logger.Error("Error writing to response", "err", err) ctx.Logger.Error("Error writing to response", "err", err)
} }
......
...@@ -264,5 +264,9 @@ func (df *dataFrames) MarshalJSON() ([]byte, error) { ...@@ -264,5 +264,9 @@ func (df *dataFrames) MarshalJSON() ([]byte, error) {
return nil, err return nil, err
} }
return jsoniter.Marshal(encoded) // Use a configuration that's compatible with the standard library
// to minimize the risk of introducing bugs. This will make sure
// that map keys is ordered.
jsonCfg := jsoniter.ConfigCompatibleWithStandardLibrary
return jsonCfg.Marshal(encoded)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment