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}

Article author: Andrei Olegovich

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

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: