Skip to content

Simple query doesn't work #36

@retr0h

Description

@retr0h

I can't seem to make a simple query work.

jsonpath2 version

jsonpath2==0.4.1

Platform Details

Mac OS

Steps to Reproduce:

import json
import jsonpath2 as jsonpath

k = {'foo': ['bar', 'baz']}

j = json.dumps(k)
__filter = '$.foo[0]'

print([m.current_value for m in jsonpath.match(__filter, j)])

Output

[jodewey:~/git/ansiblectl]   : host-filtering(+25/-2)+* ± python ansiblectl/cmd/test.py
[]

Changing the filter to '$' results in:

['{"foo": ["bar", "baz"]}']

Ultimately I'm trying to simply query a list but nothing seems to work.

import json
import jsonpath2 as jsonpath

k = ['bar', 'baz']

j = json.dumps(k)
__filter = '$[0]'

print([m.current_value for m in jsonpath.match(__filter, j)])
[jodewey:~/git/ansiblectl]   : host-filtering(+25/-2)+* ± python ansiblectl/cmd/test.py
[]

These queries work perfectly fine on https://jsonpath.com/

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