Home > database >  How to iterate to json object and gets its array using robot framework
How to iterate to json object and gets its array using robot framework

Time:03-22

Successfully stored it to array list

I want to Iterate on Locationlist and get its country type and bikeList bike type and text.

    {
"addedToList": {
    "locationList": [
        {
            "countryType": "US"
            "LineList": [
                {
                    "Text": "thequickbrownfoxjumps over the lazy dog"
                }
            ]
        }
    ],
    "bikeList": [
        {
            "BikeType": "road"
            "LineList": [
                {
                    "Text": "text"

                }
            ]
        }
    ]
},
"addedLine": "2"
}

CodePudding user response:

If want with pure robotframework, you could check robotframework-jsonlibrary

An example robot case to access your json file's country:

*** Settings ***
Library     JSONLibrary
Library     Collections

*** Test Cases ***
Test For Json
    ${json_obj} =   Load JSON From File     example.json
    ${countries} =  Get Value From Json     ${json_obj}     $..countryType
    @{countries} =  Convert To List         ${countries}
    FOR     ${country}     IN      @{countries}
        Log To Console      ${country}
    END

And what's more, if you're familiar with extending robot's keywords with python, you could also write your own keywords by python.

CodePudding user response:

use JSON [https://goessner.net/articles/JsonPath/][query selector] $..locationList[?(@.countryType)].countryType to filter all country type under selected object

  • Related