Robot Framework JSONLibrary
robotframework-jsonlibrary is a Robot Framework test library designed for manipulating JSON objects within test automation scripts. It leverages JSONPath expressions for efficient querying, adding, updating, and deleting data within JSON structures. The current version is 0.5, with releases occurring sporadically, indicating active maintenance.
Warnings
- breaking Python 2 support was dropped starting with version 0.4. Users on Python 2 must either upgrade their Python environment or use an older version of the library (pre-0.4).
- breaking Prior to version 0.5, some keywords that modified JSON objects (e.g., `Add Object To Json`) would modify the object in-place. As of version 0.5, these keywords now consistently return the modified JSON object, requiring users to capture the return value.
- gotcha This library acts as a bridge to the `jsonpath-ng` parser. Any issues encountered with JSONPath parsing behavior should be reported directly to the `jsonpath-ng` repository, not `robotframework-jsonlibrary`.
- gotcha The underlying `jsonpath-ng` library has a dependency `ply`, which has been flagged with high-severity vulnerabilities (e.g., 9.8). Users should be aware of this transitive dependency risk.
Install
-
pip install -U robotframework-jsonlibrary
Imports
- JSONLibrary
*** Settings *** Library JSONLibrary
Quickstart
resource.robot
*** Settings ***
Library JSONLibrary
*** Test Cases ***
Example JSON Manipulation
${json_obj}= Create Dictionary name=Alice age=30 city=New York
Log Initial JSON: ${json_obj}
# Add a new field
${updated_json}= Add Object To Json ${json_obj} $.email alice@example.com
Log JSON after adding email: ${updated_json}
# Get a value
${name}= Get Value From Json ${updated_json} $.name
Should Be Equal As Strings ${name} Alice
Log Name retrieved: ${name}
# Update a value
${final_json}= Update Value To Json ${updated_json} $.age 31
Log JSON after updating age: ${final_json}
# Verify update
${updated_age}= Get Value From Json ${final_json} $.age
Should Be Equal As Strings ${updated_age} 31