dfilatov / jspath

DSL that enables you to navigate and find data within your JSON documents
MIT License
553 stars 40 forks source link

"array does not contain" type filtering #70

Closed Twinbird24 closed 6 years ago

Twinbird24 commented 6 years ago

Given a data set like this:

{
    title: "obj1",
    category: [
        "general",
        "feed",
        "repairs"
    ]
},
{
    title: "obj2",
    category: [
        "general",
        "feed"
    ]
}

How would I filter to get all objects in which category contains "feed" (which is simply .category*="feed") AND also does not contain "repairs"? Something like .category*="feed"&&.category!*="repairs" (which isn't valid) or .category*="feed"&&.category!="repairs" (but this still returns both objects above).

Is this something that is possible?

dfilatov commented 6 years ago

Hi, @Twinbird24 Try out this path: '.{.category === "feed" && !(.category === "repairs")}'

!(.category === "repairs") means "where there's no any category is equal to repairs", unlike .category !== "repairs" which means "where at least one category isn't equal to repairs

That behaviour has come from XPath.

Twinbird24 commented 6 years ago

That makes sense, thank you!