diff --git a/client/document.go b/client/document.go index 3105e5a2fb..f8d427c349 100644 --- a/client/document.go +++ b/client/document.go @@ -13,6 +13,7 @@ package client import ( "encoding/json" "errors" + "regexp" "strings" "sync" "time" @@ -117,11 +118,11 @@ func NewDocFromMap(data map[string]any, collectionDefinition CollectionDefinitio return doc, nil } +var jsonArrayPattern = regexp.MustCompile(`(?s)^\s*\[.*\]\s*$`) + // IsJSONArray returns true if the given byte array is a JSON Array. func IsJSONArray(obj []byte) bool { - var js []any - err := json.Unmarshal(obj, &js) - return err == nil + return jsonArrayPattern.Match(obj) } // NewFromJSON creates a new instance of a Document from a raw JSON object byte array. diff --git a/client/document_test.go b/client/document_test.go index 450a181af0..a11a6a67c8 100644 --- a/client/document_test.go +++ b/client/document_test.go @@ -252,9 +252,10 @@ func TestIsJSONArray(t *testing.T) { name: "Valid JSON Array with Whitespace", input: []byte(` [ - {"name": "John", "age": 21}, - {"name": "Islam", "age": 33} - ]`), + { "name": "John", "age": 21 }, + { "name": "Islam", "age": 33 } + ] + `), expected: true, }, }