Files
deb-python-gabbi/docs/source/jsonpath.rst
Chris Dent b12a6a1672 Starts tests and docs on JSONPath len extension
I'm not entirely happy with the docs page, but decided something was
better than nothing.
2015-08-04 19:01:06 +01:00

1.2 KiB

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 example.