tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
13.88k stars 841 forks source link

Retrieving data based on length of the string fields #320

Open ngarg-kr opened 1 year ago

ngarg-kr commented 1 year ago

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"]}
  ]
}

I need the last name of those friends whose first name is of 5 characters which will be Craig in this case.

@tidwall is this possible to write such query?

volans- commented 1 year ago

@ngarg-kr I didn't try it, but I think that if you register a custom modifier to calculate the length, let's say @len, you might be able to get what you're looking for with:

friends.#(first.@len==5)#.last