Skip to content

filter with a boolean value doesn't work #40

Description

@andrew-ares

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions