Easy way to load json file and read value from it robotframework

Techie,

Many of the times we came across the situations where we need to load file of constants, data etc and read key , value from it.

Below is sample json file

{
  "firstname": "hardik",
 "lastname":"dave"
}

Concern robot code

*** Settings ***

Library    SeleniumLibrary  
Library    HttpLibrary.HTTP
Library    OperatingSystem
Library    Collections

Resource    ../../Data/AppGeneric.json [Your path of json file goes here]

*** Variables ***

*** Keywords ***

Load Json
    ${file}    Get File    PATH/AppGeneric.json
    ${qa}    Evaluate    json.loads('''${file}''')    json
    Log    ${qa["firstname"]}
   

It will print Hardik here ,

Same way one can easily get any dictionary value.


Comments

Popular Posts