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.
This commit is contained in:
Marcus Efraimsson 2021-01-29 15:31:19 +01:00 committed by GitHub
parent 9407cdd51c
commit f62eb28f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -102,7 +102,12 @@ func (r StreamingResponse) WriteTo(ctx *models.ReqContext) {
header[k] = v
}
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 {
ctx.Logger.Error("Error writing to response", "err", err)
}

View File

@ -264,5 +264,9 @@ func (df *dataFrames) MarshalJSON() ([]byte, error) {
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)
}