Search for a field content with json

I have structure with a filed named named “languages” where we can have N languages with the level. For example:
1[description: “english”, level : “9”]
2[description: “italian”, level: “5”]

Is possible do a search looking in the “languages” field with the next predicate "where language is “french” with level greater than 4 or language is “italian” with level greater than “3”?

Thanks a lot in advance!

You can use a JSONPath filter, (see docs on ?() filter and examples) e.g.,

With this:> JSON.SET k1 $ '{"languages":[{"description":"english","level":9},{"description":"italian","level":5}]}'
OK> JSON.SET k2 $ '{"languages":[{"description":"french","level":9},{"description":"italian","level":2}]}'
OK> JSON.SET k3 $ '{"languages":[{"description":"english","level":9},{"description":"italian","level":2}]}'

You can filter like this:> JSON.GET k1 '$.languages[?((@.description=="french" && @.level>4)||(@.description=="italian" && @.level>3))]'
"[{\"description\":\"italian\",\"level\":5}]"> JSON.GET k2 '$.languages[?((@.description=="french" && @.level>4)||(@.description=="italian" && @.level>3))]'
"[{\"description\":\"french\",\"level\":9}]"> JSON.GET k3 '$.languages[?((@.description=="french" && @.level>4)||(@.description=="italian" && @.level>3))]'
1 Like

Thanks @oshadmi, I will try it :+1: