A Robot Framework library providing high-performance JSON querying using JMESPath expressions.
JMESPath offers significant advantages over JSONPath for Robot Framework testing:
- Better Performance: Native Python implementation with superior performance
- More Powerful: Rich filtering, projections, and transformations
- Better Maintained: Active development and strong community support
- Simpler Syntax: Cleaner, more intuitive query expressions
- Standardized: Well-defined specification and behavior
pip install robotframework-jmespath*** Settings ***
Library JMESPathLibrary
*** Test Cases ***
Query JSON Data
${json}= Evaluate {"users": [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]}
${name}= JSON Search String ${json} users[0].name
Should Be Equal ${name} Alice
${names}= JSON Search List ${json} users[*].name
Should Contain ${names} Alice
Should Contain ${names} BobExecute a JMESPath query and return a single string result.
Arguments:
data: JSON data to query (dict, list, or JSON string)expression: JMESPath expression
Returns: String value (first result if multiple matches), or empty string if no match
Examples:
${tenant}= JSON Search String ${response} imdata[0].fvTenant.attributes.name
${ip}= JSON Search String ${response} imdata[0].fvBD.children[?fvSubnet] | [0].fvSubnet.attributes.ipExecute a JMESPath query and return results as a list.
Arguments:
data: JSON data to query (dict, list, or JSON string)expression: JMESPath expression
Returns: List of results, or empty list if no matches
Examples:
${names}= JSON Search List ${response} imdata[0].fvTenant.children[*].fvAp.attributes.name
${ips}= JSON Search List ${response} imdata[0].fvBD.children[*].fvSubnet.attributes.ip| Operation | Example | Description |
|---|---|---|
| Object access | foo.bar |
Access nested object |
| Array access | foo[0] |
Access array element |
| Array slice | foo[0:2] |
Slice array |
| Wildcard | foo[*].bar |
All array elements |
| Filter | foo[?bar=='value'] |
Filter array |
| Pipe | foo | [0] |
Chain expressions |
Access nested object:
imdata[0].fvTenant.attributes.name
Filter array by attribute:
imdata[0].fvTenant.children[?fvAp.attributes.name=='AP1'] | [0]
Get all names from array:
imdata[0].fvTenant.children[*].fvAp.attributes.name
Filter with multiple conditions:
users[?age > `25` && active == `true`]
| Feature | JSONPath | JMESPath |
|---|---|---|
| Root | $ |
(implicit) |
| Child access | $.foo.bar |
foo.bar |
| Recursive descent | $..field |
Not supported* |
| Array filter | $[?(@.age > 25)] |
[?age > \25`]` |
| Wildcard | $.* |
* or [*] |
| Pipe/Chain | Not supported | foo | [0] |
*For recursive descent, use explicit paths: children[?fvAp]
*** Settings ***
Library RequestsLibrary
Library JMESPathLibrary
*** Test Cases ***
Verify Tenant Configuration
# Make API call
${response}= GET On Session apic /api/mo/uni/tn-TENANT1.json params=rsp-subtree=full
${json}= Set Variable ${response.json()}
# Query with JMESPath
${tenant_name}= JSON Search String ${json} imdata[0].fvTenant.attributes.name
Should Be Equal ${tenant_name} TENANT1
# Query nested objects
${ap_name}= JSON Search String ${json}
... imdata[0].fvTenant.children[?fvAp.attributes.name=='AP1'] | [0].fvAp.attributes.name
Should Be Equal ${ap_name} AP1
# Get all subnet IPs
${subnets}= JSON Search List ${json}
... imdata[0].fvTenant.children[*].fvBD.children[*].fvSubnet.attributes.ip
Should Contain ${subnets} 10.0.0.1/24# Clone repository
git clone https://github.com/netascode/robotframework-jmespath.git
cd robotframework-jmespath
# Install in development mode
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install# Run all tests (unit tests + robot tests via pytest wrapper)
pytest tests/
# Run unit tests only
pytest tests/test_unit.py
# Run robot acceptance tests directly
robot tests/acceptance.robot
# Run acceptance tests via pytest wrapper
pytest tests/test_acceptance.py
# Run with coverage
pytest --cov=JMESPathLibrary tests/
# Run linters
ruff check .
mypy .
bandit -r JMESPathLibrary/This project uses:
- ruff for linting and formatting
- mypy for type checking
- bandit for security analysis
- pytest for testing
- pre-commit for git hooks
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run the test suite
- Submit a pull request
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.
- Oliver Boehmer (@oboehmer)
- Inspired by the need for high-performance JSON querying in network automation testing
- Built on the excellent jmespath.py library
- Part of the Network-as-Code ecosystem