Robot Framework JSONLibrary

0.5 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This Robot Framework example demonstrates basic JSON manipulation. It creates a JSON object (as a Robot Framework dictionary), adds a new field using `Add Object To Json`, retrieves a value with `Get Value From Json`, and updates an existing field using `Update Value To Json`. The `Should Be Equal As Strings` keyword is used for assertions. This code is designed to be placed in a `.robot` file.

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

view raw JSON →