JSON

Contents
Introduction
Example
Related Articles

Introduction

Example

You need to read the file from the robot users.json and parse its contents

Project structure

json/ ├── data │ └── users.json └── src └── json.robot 2 directories, 2 files

{ "users": [{ "username": "tester0", "password": "secret0", "firstname": "Dmitry", "lastname": "Mendeleev", "phone": 12345 }, { "username": "tester1", "password": "secret0", "firstname": "Nikolai", "lastname": "Basov", "phone": 12346 } ] }

Robot Framework

*** Settings *** Library OperatingSystem Library Collections *** Test Cases *** Loading JSON ${json}= Get File ../users.json ${object}= Evaluate json.loads('''${json}''') json Log To Console ${object["users"][0]["username"]} &{user0}= Convert To Dictionary ${object["users"][0]} Log To Console ${user0}

robot json_from_file.robot

============================================================================== Json ============================================================================== Loading JSON ..tester0 ..{'username': 'tester0', 'password': 'secret0', 'firstname': 'Dmitry', 'lastname': 'Mendeleev', 'phone': 12345} Loading JSON | PASS | ------------------------------------------------------------------------------ Json | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /home/andrei/sandbox/robot/json/src/output.xml Log: /home/andrei/sandbox/robot/json/src/log.html Report: /home/andrei/sandbox/robot/json/src/report.html

You can specify the path from the current directory using Normalize Path and CURDIR

${path}= Normalize path ${CURDIR}/../../../../data/users.json ${json}= Get File ${path}

Related Articles
Robot Framework
Basics
RFBrowser
Set Variable
if else: conditionals
in: check if smth belongs to list
Loops
Change Variable Value
New Line
[Tags]
Collections: lists, dicts
JSON
Pass Argument to a Keyword
Evaluate
Robot in PyCharm
Banner Image

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat