Open SriHemnath opened 2 years ago
{ "data":{ "outcomes":[ { } ] } }
Outcomes is an empty array and if we call Exists() it will return true because it will have [] in it and len function returns true. It should return false as array is empty.
[]
data, err := ioutil.ReadFile("array.json") if err != nil { fmt.Println("Error while reading file ", err) } fmt.Println("Read successfully: ", string(data)) actionTypeEntries := gjson.GetBytes(data, "data.outcomes.#.action.type") fmt.Println(len(actionTypeEntries.Raw)) if actionTypeEntries.Exists() { fmt.Println("has value") } else { fmt.Println("No values") }
This PR is to fix this issue.
The actionTypeEntries results in the empty array [].
actionTypeEntries
An empty array technically exists, even though it's empty.
Outcomes is an empty array and if we call Exists() it will return true because it will have
[]
in it and len function returns true. It should return false as array is empty.This PR is to fix this issue.