GithubHelp home page GithubHelp logo

jmespathv041p's Introduction

JMESPath

JMESPath (pronounced \ˈjāmz path\) allows you to declaratively specify how to extract elements from a JSON document.

For example, given this document:

{"foo": {"bar": "baz"}}

The jmespathv041p expression foo.bar will return "baz".

JMESPath also supports:

Referencing elements in a list. Given the data:

{"foo": {"bar": ["one", "two"]}}

The expression: foo.bar[0] will return "one". You can also reference all the items in a list using the * syntax:

{"foo": {"bar": [{"name": "one"}, {"name": "two"}]}}

The expression: foo.bar[*].name will return ["one", "two"]. Negative indexing is also supported (-1 refers to the last element in the list). Given the data above, the expression foo.bar[-1].name will return "two".

The * can also be used for hash types:

{"foo": {"bar": {"name": "one"}, "baz": {"name": "two"}}}

The expression: foo.*.name will return ["one", "two"].

NOTE: jmespathv041p is being actively developed. There are a number of features it does not currently support that may be added in the future.

Specification

The grammar is specified using ABNF, as described in RFC4234. You can find the most up to date grammar for JMESPath here.

You can read the full JMESPath specification here http://jmespathv041p.readthedocs.org/en/latest/specification.html__.

Testing

In addition to the unit tests for the jmespathv041p modules, there is a tests/compliance directory that contains .json files with test cases. This allows other implementations to verify they are producing the correct output. Each json file is grouped by feature.

Python Library

The included python implementation has two convenience functions that operate on python data structures. You can use search and give it the jmespathv041p expression and the data:

>>> import jmespathv041p
>>> path = jmespathv041p.search('foo.bar', {'foo': {'bar': 'baz'}})
'baz'

Similar to the re module, you can store the compiled expressions and reuse them to perform repeated searches:

>>> import jmespathv041p
>>> path = jmespathv041p.compile('foo.bar')
>>> path.search({'foo': {'bar': 'baz'}})
'baz'
>>> path.search({'foo': {'bar': 'other'}})
'other'

You can also use the jmespathv041p.parser.Parser class directly if you want more control.

jmespathv041p's People

Contributors

jamesls avatar mtdowling avatar henrysher avatar lsegal avatar trevorrowe avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.