Skip to content

filter with a boolean value doesn't work #40

@andrew-ares

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions