From 498f1a3ef09bfb658c3c24a9d0954c5e4aeb0eed Mon Sep 17 00:00:00 2001 From: Tarun Khandelwal Date: Mon, 19 Jul 2021 23:19:01 +0530 Subject: [PATCH] chore: add function to get []*unstructured.Unstructured from json array --- utils.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils.go b/utils.go index c4d1a2e..4d833e9 100644 --- a/utils.go +++ b/utils.go @@ -2,6 +2,7 @@ package kommons import ( "bytes" + "encoding/json" "fmt" "reflect" "strings" @@ -664,6 +665,14 @@ func GetUnstructuredObjects(data []byte) ([]*unstructured.Unstructured, error) { return items, nil } +func GetUnstructuredObjectsFromJson(data []byte) ([]*unstructured.Unstructured, error) { + var items []*unstructured.Unstructured + if err := json.Unmarshal(data, &items); err != nil { + return nil, err + } + return items, nil +} + // GetCurrentClusterNameFrom returns the name of the cluster associated with the currentContext of the // specified kubeconfig file func GetCurrentClusterNameFrom(kubeConfigPath string) string {