gjson icon indicating copy to clipboard operation
gjson copied to clipboard

Retrieve field values with multiple conditions

Open ngarg-kr opened this issue 1 year ago • 5 comments

For a sample payload like this:

{
  "name": {"first": "Tom", "last": "Anderson"},
  "age":37,
  "children": ["Sara","Alex","Jack"],
  "fav.movie": "Deer Hunter",
  "friends": [
    {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
    {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
    {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
  ]
}

If we want to get the age of friend whose last name isMurphy and first name is Dale then what gjson expression will give that result.

I tried friends.#(last == "Murphy" && first == "Dale")#.age but it gives an empty array in response.

@tidwall kindly help regarding this

ngarg-kr avatar Mar 21 '23 11:03 ngarg-kr