1
votes

I am trying parse json file using robot framework and Httplibrary but while parsing I am facing issue. Please find below output section for more details and please let me know possible solution.

Input file to read sample.json

{
    "age":100,
    "name":"mkyong.com",
    "messages":["msg 1","msg 2","msg 3"]
}

Code for robot framework

*** Settings ***
    Documentation                 Test our very first REST API
    Library                       HttpLibrary.HTTP
    Library                       OperatingSystem


*** Test Cases ***

Create Question Should Return Success

  Created Question Details Should Be Correct

*** Keywords ***

Created Question Details Should Be Correct
  ${expectation} =                      Parse Json From File
  Log    ${expectation}


Parse Json From File
  ${file} =                             Get File    sample.json
  ${json} =                             Parse Json    ${file}
  [Return]                              ${json}

But Getting below output after parsing json file:

{
    u'age':100,
    u'name':u'mkyong.com',
    u'messages':[u'msg 1',u'msg 2',u'msg 3']
}
1

1 Answers

0
votes

The Parse Json keyword is supposed to return a data structure which means it is behaving exactly as it should.

Try retrieving some of your values:

Parse Json From File
  ${file} =                             Get File    sample.json
  ${json} =                             Parse Json    ${file}
  Log                                   Get Json Value    ${json}    /age
  Log                                   Get Json Value    ${json}    /name
  Log                                   Get Json Value    ${json}    /messages
  [Return]                              ${json}