cancel
Showing results for 
Search instead for 
Did you mean: 

how to read values from json file as we can from Excel or .txt file

SOLVED
Contributor

how to read values from json file as we can from Excel or .txt file

Hi,

 

I am trying to read the values from .json file format by using Data Source Step. By it says file format unsupported.

 

I am successfully able to read values using Excel and Text file. Is it possible to read values from .json file format.

 

Thanks a lot in advance.

 

Regards,

Shasha

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Re: how to read values from json file as we can from Excel or .txt file

Hi,

 

When creating the datasource, you have noted that whilst JSON is an option, there is no way to read in from files.  So, do that.

 

Firstly, create a Groovy step.  In the Step return the contents of the JSON file.

 

 

def file1 = new File('C:/temp/temp.json');

return file1.text;

 

 

If you run this step on its own, you should get a pop-up that shows the contents of the file.  If you don't check the path and file name.

 

Then, create your data source step.  Select JSON from the DataSource dropdown.  Then, from the 'Source Step' dropdown, select the Groovy step created earlier.  From the Source Property dropdown, select 'Result'.

 

From here, you just need to define the properties of the JSON object.

6 REPLIES 6
Occasional Contributor

Re: how to read values from json file as we can from Excel or .txt file

Hi,

 

When creating the datasource, you have noted that whilst JSON is an option, there is no way to read in from files.  So, do that.

 

Firstly, create a Groovy step.  In the Step return the contents of the JSON file.

 

 

def file1 = new File('C:/temp/temp.json');

return file1.text;

 

 

If you run this step on its own, you should get a pop-up that shows the contents of the file.  If you don't check the path and file name.

 

Then, create your data source step.  Select JSON from the DataSource dropdown.  Then, from the 'Source Step' dropdown, select the Groovy step created earlier.  From the Source Property dropdown, select 'Result'.

 

From here, you just need to define the properties of the JSON object.

Frequent Contributor

Re: how to read values from json file as we can from Excel or .txt file

Hello @ChrisA 

 

I needed this too bur I get an error message in ReadyAPI version 2.6.0:

groovyscript.png

 

What did I do wrong please? or what should I do?

If I run the groovy script I indeed have an overview of my json file.

 

Thanks in advance.

 

 

Occasional Contributor

Re: how to read values from json file as we can from Excel or .txt file

Hi,

 

Doesn't look like a SoapUI error.  Have you done as it suggests and check your data for numeric values with leading zeroes?

Frequent Contributor

Re: how to read values from json file as we can from Excel or .txt file

Hi @ChrisA 

Indeed, my architect just explained that our Mock server and Swagger also cry their eyes out because of number starting with zero. So we will make those numbers as string in the file. You think that could solve my problem?

 

KindRegards,

AAB

Occasional Contributor

Re: how to read values from json file as we can from Excel or .txt file

There's only one way to find out!!

Community Manager

Re: how to read values from json file as we can from Excel or .txt file

Hi @Shashavali,

 

@ChrisA's suggestion looks good. Try using it.

 

Also, I suggest that you submit a feature request to implement this feature in ReadyAPI:

https://community.smartbear.com/t5/ReadyAPI-Feature-Requests/idb-p/ReadyAPIFeatureRequests

If the suggestion gets many votes, our Product Team will consider implementing it.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors