diff --git a/api/base.go b/api/base.go index df303b945..d40512cb3 100644 --- a/api/base.go +++ b/api/base.go @@ -500,3 +500,20 @@ func (r *Cursor) pageLimited() (b bool) { b = r.Index > int64(r.Limit) return } + +// +// StrMap returns a map[string]any. +// The YAML decoder can produce map[any]any which is not valid for json. +// Converts map[any]any to map[string]any as needed. +func StrMap(in any) (out any) { + out = in + if d, cast := in.(map[any]any); cast { + mp := make(map[string]any) + for k, v := range d { + s := fmt.Sprintf("%v", k) + mp[s] = StrMap(v) + } + out = mp + } + return +} diff --git a/api/task.go b/api/task.go index 1495b2f3a..18aca35f3 100644 --- a/api/task.go +++ b/api/task.go @@ -586,7 +586,7 @@ func (r *Task) Model() (m *model.Task) { State: r.State, ApplicationID: r.idPtr(r.Application), } - m.Data, _ = json.Marshal(r.Data) + m.Data, _ = json.Marshal(StrMap(r.Data)) m.ID = r.ID if r.TTL != nil { m.TTL, _ = json.Marshal(r.TTL) @@ -642,7 +642,7 @@ func (r *TaskReport) Model() (m *model.TaskReport) { m.Activity, _ = json.Marshal(r.Activity) } if r.Result != nil { - m.Result, _ = json.Marshal(r.Result) + m.Result, _ = json.Marshal(StrMap(r.Result)) } if r.Errors != nil { m.Errors, _ = json.Marshal(r.Errors) diff --git a/api/taskgroup.go b/api/taskgroup.go index f137466a3..c494743bd 100644 --- a/api/taskgroup.go +++ b/api/taskgroup.go @@ -399,7 +399,7 @@ func (r *TaskGroup) Model() (m *model.TaskGroup) { State: r.State, } m.ID = r.ID - m.Data, _ = json.Marshal(r.Data) + m.Data, _ = json.Marshal(StrMap(r.Data)) m.List, _ = json.Marshal(r.Tasks) if r.Bucket != nil { m.BucketID = &r.Bucket.ID