File: jsonpath.rst

package info (click to toggle)
python-gabbi 1.12.0-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 588 kB
  • sloc: python: 1,782; makefile: 212; sh: 44
file content (41 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

JSONPath
========

Gabbi makes extensive use of JSONPath to provide a tool for
validating response bodies that are formatted as JSON and making
reference to that JSON in subsequent queries. `jsonpath_rw`_ is used
to process the JSONPath expressions.

To address a common requirement when evaluting JSON responses, an
extension has been made to the default implementation of JSONPath.
This extension is ``len`` and will return the length of the current
datum in the JSONPath expression.

Here is a simple JSONPath example, including use of ``len``. Given JSON data
as follows::

    {
        "alpha": ["one", "two"],
        "beta": "hello"
    }

it is possible to get information about the values and length as
follows::

    response_json_paths:
        # the dict has two keys
        $.`len`: 2
        # The elements of the alpha list
        $.alpha[0]: one
        $.alpha.[1]: two
        # the alpha list has two items
        $.alpha.`len`: 2
        # The string at beta is hello
        $.beta: hello
        # The string at beta has five chars
        $.beta.`len`: 5

There are more JSONPath examples in :doc:`example`.

.. _jsonpath_rw: http://jsonpath-rw.readthedocs.org/en/latest/