Skip to content

vamitrou/jpath-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jpath-py

XPath-like querying for JSON. Written in python

Example:

d={
    "students": [
        {
            "name": "bob",
            "projects": [
                {
                    "name": "banana"
                },
                {
                    "name": "apple"
                }
            ]
        },
        {
            "name": "alice",
            "projects": [
                {
                    "name": "orange"
                }
            ]
        }
    ]
}

from jpathpy import jpath

# get me the second project's name of the first student
print jpath.get_dict_value(d, "students[0]/projects[1]/name")
>> apple

# get me all the project objects of the first student
print jpath.get_dict_value(d, "students[0]/projects/*")
>> [{'name': 'banana'}, {'name': 'apple'}]

# get me all the project names of all the students
print jpath.get_dict_value(d, "students/*/projects/*/name")
>> [['banana', 'apple'], ['orange']]

About

XPath-like querying for JSON. Written in python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages