MCPcopy
hub / github.com/apache/devlake / ToCleanJson

Function ToCleanJson

backend/test/helper/json_helper.go:60–89  ·  view source on GitHub ↗

ToCleanJson FIXME

(inline bool, x any)

Source from the content-addressed store, hash-verified

58
59// ToCleanJson FIXME
60func ToCleanJson(inline bool, x any) json.RawMessage {
61 j, err := json.Marshal(x)
62 if err != nil {
63 panic(err)
64 }
65 var m any
66 if j[0] == '[' {
67 //it's a slice
68 m = x
69 } else {
70 m = map[string]any{}
71 err = json.Unmarshal(j, &m)
72 if err != nil {
73 panic(err)
74 }
75 if m != nil {
76 removeNullsFromMap(m.(map[string]any))
77 }
78 }
79 var b []byte
80 if inline {
81 b, err = json.Marshal(m)
82 } else {
83 b, err = json.MarshalIndent(m, "", " ")
84 }
85 if err != nil {
86 panic(err)
87 }
88 return b
89}
90
91func removeNullsFromMap(m map[string]any) {
92 refMap := reflect.ValueOf(m)

Callers 2

monitorPipelineMethod · 0.85
sendHttpRequestFunction · 0.85

Calls 1

removeNullsFromMapFunction · 0.85

Tested by

no test coverage detected