PaesslerAG / jsonpath

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

filter with a boolean value doesn't work #40

Open TENX-S opened 1 year ago

TENX-S commented 1 year ago

Given the following json and jsonpath expression:

{
  "server": [
    {
      "key": "op_host",
      "props": {
          "isEncrypt": true
      }
    }
  ]
}

$.server[?(@.props.isEncrypt == true)].key

the following code can't achieve the desired result, but jsonpath.com can.

package main

import (
    "encoding/json"
    "fmt"
    "os"

    "github.com/PaesslerAG/jsonpath"
)

func main() {
    v := interface{}(nil)

    json.Unmarshal([]byte(`{
  "server": [
    {
      "key": "op_host",
      "props": {
          "isEncrypt": true
      }
    }
  ]
}`), &v)

    welcome, err := jsonpath.Get(`$.server[?(@.props.isEncrypt == true)].key`, &v)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(welcome)
}
image