@@ -216,6 +216,22 @@ func marshalJson(input interface{}) (string, error) {
216
216
return strings .TrimSuffix (buf .String (), "\n " ), nil
217
217
}
218
218
219
+ func unmarshalJsonArray (input string ) ([]interface {}, error ) {
220
+ var v []interface {}
221
+ if err := json .Unmarshal ([]byte (input ), & v ); err != nil {
222
+ return nil , err
223
+ }
224
+ return v , nil
225
+ }
226
+
227
+ func unmarshalJsonObject (input string ) (interface {}, error ) {
228
+ var v map [string ]interface {}
229
+ if err := json .Unmarshal ([]byte (input ), & v ); err != nil {
230
+ return nil , err
231
+ }
232
+ return v , nil
233
+ }
234
+
219
235
// arrayFirst returns first item in the array or nil if the
220
236
// input is nil or empty
221
237
func arrayFirst (input interface {}) interface {} {
@@ -285,32 +301,34 @@ func trimSuffix(suffix, s string) string {
285
301
286
302
func newTemplate (name string ) * template.Template {
287
303
tmpl := template .New (name ).Funcs (template.FuncMap {
288
- "closest" : arrayClosest ,
289
- "coalesce" : coalesce ,
290
- "contains" : contains ,
291
- "dict" : dict ,
292
- "dir" : dirList ,
293
- "exists" : exists ,
294
- "first" : arrayFirst ,
295
- "groupBy" : groupBy ,
296
- "groupByKeys" : groupByKeys ,
297
- "groupByMulti" : groupByMulti ,
298
- "hasPrefix" : hasPrefix ,
299
- "hasSuffix" : hasSuffix ,
300
- "json" : marshalJson ,
301
- "intersect" : intersect ,
302
- "keys" : keys ,
303
- "last" : arrayLast ,
304
- "replace" : strings .Replace ,
305
- "sha1" : hashSha1 ,
306
- "split" : strings .Split ,
307
- "trimPrefix" : trimPrefix ,
308
- "trimSuffix" : trimSuffix ,
309
- "where" : where ,
310
- "whereExist" : whereExist ,
311
- "whereNotExist" : whereNotExist ,
312
- "whereAny" : whereAny ,
313
- "whereAll" : whereAll ,
304
+ "closest" : arrayClosest ,
305
+ "coalesce" : coalesce ,
306
+ "contains" : contains ,
307
+ "dict" : dict ,
308
+ "dir" : dirList ,
309
+ "exists" : exists ,
310
+ "first" : arrayFirst ,
311
+ "groupBy" : groupBy ,
312
+ "groupByKeys" : groupByKeys ,
313
+ "groupByMulti" : groupByMulti ,
314
+ "hasPrefix" : hasPrefix ,
315
+ "hasSuffix" : hasSuffix ,
316
+ "json" : marshalJson ,
317
+ "intersect" : intersect ,
318
+ "keys" : keys ,
319
+ "last" : arrayLast ,
320
+ "replace" : strings .Replace ,
321
+ "parseJsonArray" : unmarshalJsonArray ,
322
+ "parseJsonObject" : unmarshalJsonObject ,
323
+ "sha1" : hashSha1 ,
324
+ "split" : strings .Split ,
325
+ "trimPrefix" : trimPrefix ,
326
+ "trimSuffix" : trimSuffix ,
327
+ "where" : where ,
328
+ "whereExist" : whereExist ,
329
+ "whereNotExist" : whereNotExist ,
330
+ "whereAny" : whereAny ,
331
+ "whereAll" : whereAll ,
314
332
})
315
333
return tmpl
316
334
}
0 commit comments