From 456ca5e93369ce2a8893ce383ada0c93ccb61150 Mon Sep 17 00:00:00 2001 From: Joe Rodriguez Date: Thu, 18 Jan 2024 14:10:01 -0700 Subject: [PATCH] bugfix: to_array parses marshalled json --- compliance/functions.json | 4 ++++ functions.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/compliance/functions.json b/compliance/functions.json index 8b8db36..8bd806b 100644 --- a/compliance/functions.json +++ b/compliance/functions.json @@ -467,6 +467,10 @@ "expression": "to_array(objects)", "result": [{"foo": "bar", "bar": "baz"}] }, + { + "expression": "to_array(to_string(objects))", + "result": [{"foo": "bar", "bar": "baz"}] + }, { "expression": "to_array(`[1, 2, 3]`)", "result": [1, 2, 3] diff --git a/functions.go b/functions.go index e9770e8..2a27370 100644 --- a/functions.go +++ b/functions.go @@ -793,6 +793,13 @@ func jpfToArray(arguments []interface{}) (interface{}, error) { if _, ok := arguments[0].([]interface{}); ok { return arguments[0], nil } + if asString, ok := arguments[0].(string); ok { + var unmarshalled interface{} + err := json.Unmarshal([]byte(asString), &unmarshalled) + if err == nil { + return []interface{}{unmarshalled}, err + } + } return arguments[:1:1], nil } func jpfToString(arguments []interface{}) (interface{}, error) {