Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Script to capture JSON elements in Excel

Options
Abhi
Abhi Posts: 2

Hi Team,
I have a situation where i have to fetch the values from JSON response and write those in excel in different predefined columns. I have created JSON data bank and captured the required values. Then i add an extension tool to fetch the data bank values , but now not able to write those values in excel . Need help !
Please find below the Jython code i have created .
from com.parasoft.api import *;
from soaptest.api import *;
from java.util import *;

def readData(input, context):
#data = addDataSource(context)
val1 = context.getValue("Generated Data Source", "Test 1: viccVehicleCd")
val2 = context.getValue("Generated Data Source", "Test 1: viccExtensionCd")
#val3 = context.getValue("ww", "index")
#Application.showMessage(str(val3))
#return val3
# return val1
#return val1
#arraycd = ArrayList()
#arraycd.add(val1)

#for index in arraycd:
    #Application.showMessage(index)
    #Application.showMessage(id)

context.put(val1,"test")

 Note : i also used Write file to generate csv file but that is of not much use for my scenario.   
Tagged:

Comments

  • OmarR
    OmarR Posts: 234 admin
    Options

    Hey Abhi! Happy New Years!!!!!

    The simplest way to accomplish your scenario is to store your extracted-data into a writable-datasource and manually import it into an Excel or CSV file.

    That being said, there IS another way to import data into a CSV file using the almighty.....XPATH! I did a quick search on our forum and found an example on how to go about this!
    http://forums.parasoft.com/discussion/2698

  • Abhi
    Abhi Posts: 2
    Options

    Thank you Omar !
    But our situation is bit different . We have around 10,000 sets of data and it would be tedious to manually put the data in excel. Also we want to make the framework dynamic.
    For the second option you provided , we have JSON responses , so XPath is not suitable here , we have to work with JSON databank.
    We are able to create the framework using Java and can create the Request XML files :)
    Now , not sure , how to automate this part where we can pass the Xml files as request for the REST service. In SOAtest we have an option to pass one XML file as request at a time , but could you please help to provide any solution where we can pass multiple files one by one without manual intervention as we do while data parameterization.

    Thanks,
    Abhishek

Tagged