PaesslerAG / jsonpath

BSD 3-Clause "New" or "Revised" License
172 stars 37 forks source link

Does this library support regular expressions? or will it in the future? #11

Closed moshevi closed 5 years ago

generikvault commented 5 years ago

Merge jsonpath with gval.Text() or gval.Full() for Regex support. For latter is in example in the godoc.

You find regex operators in the godoc of gval.Text(): https://godoc.org/github.com/PaesslerAG/gval#Text

moshevi commented 5 years ago

But currently it's not supported out of the box as jsonpath expression?

generikvault commented 5 years ago

You can use it via: `builder := gval.Full(jsonpath.Language())

path, err := builder.NewEvaluable("$..[?@ =~ \"[fF][oO]+\"]")`

RegEx is not part of the JSonPath specification so I'm not planning to add it into jsonpath.Language()

moshevi commented 5 years ago

Thanks generikvault for your answers

moshevi commented 5 years ago

@generikvault Just another filter question: Can I filter an object attribute value or just an array one. For example I have this JSON: {"a":1, "b":2} How can I get a yes/no one-liner JsonPath expression that will return true for a==1 and false for a==2 ?

generikvault commented 5 years ago

What do you want to achieve? $.a == 1 returns true or false as descibed.

If you want to filter for a specific Object let's say in {"x":{"a":1, "b":2},"y":{"a":2, "b":3}} you can do this with $[@.a == 1]

moshevi commented 5 years ago

Thanks @generikvault