How to compare is json data is subset of another large json data using Robot framework ?
Hi @Adhavan,
Robot Framework uses python for conditional evaluation, so the same as you would in python.
Here are some examples (you can just save this as is to a .robot file and run it to see the results)
*** Variables ***
@{Fruits} Strawberry Durian Apple Guava Blueberry Papaya Tomato Avocado Orange
&{fruitstand} Strawberry=65 Durian=13 Apple=15 Guava=5 Blueberry=100 Papaya=8 Tomato=88 Avocado=99 Orange=44
&{cars} Citroën=2 Peugeot=0 Daihatsu=1 Toyota=1 Mazda=2 Honda=1
&{drinks} Coffee=White Tea=Green Beer=Yellow Wine=Red
@{listdic} &{fruitstand} &{cars} &{drinks}
*** Test Cases ***
Item in List
${mybool}= Evaluate "Avocado" in ${Fruits}
IF "Tomato" in ${Fruits}
Log Fresh Tomato on toast
END
Key in Dictonary
${mybool}= Evaluate "Blueberry" in ${fruitstand}
Value in Dictonary
${mybool}= Evaluate "13" in ${fruitstand}.values()
${mybool}= Evaluate "69" in ${fruitstand}.values()
Dictonary in List
${mybool}= Evaluate ${drinks} in ${listdic}
Hope that helps,
Dave.
Thanks Dave ! I will try it
Hi @Adhavan,
I forgot to mention
If you are using Requests Library it handles the conversion of the json string data into dictionary/list objects and back again for you
Otherwise there is jsonlibrary for converting json files / strings into dictionary/list objects and back again
Alternatively you can use the native json python module in robot framework as shown in the accepted answer in this stackoverflow thread
Or the Robocorp json library
So many options
Dave.
okay…i will try out this options thanks again