Ask a Question

Pass null from excel spreadsheet Datasource into JSON??

dief123
Occasional Contributor

Pass null from excel spreadsheet Datasource into JSON??

Any ideas on how to specify NULL in Excel spreadsheet so it gets transferred to JSON in ReadyAPI, SoapUI NG Pro?

 

JSON:

{"SBCCommunicationDetails": [{
   "CompassionSBCId": "C0028902042",
   "GlobalPartnerSBCId": ${DataSource#GlobalPartnerSBCId},

   "SourceSystem": "SDL",

...

 

I want this field to end up looking like this in JSON -  "GlobalPartnerSBCId": NULL,

However, no matter how I try to specify the NULL in the Excel spreadsheet, it will not populate like this.

I either get "GlobalPartnerSBCId": "NULL", or ""

 

Any ideas?  In the spreadsheet I have tried these values:

 

NULL, blank, {}, [], 0, "NULL", {NULL}

 

 

 

 

 

 

 

 

8 REPLIES 8
dief123
Occasional Contributor

what is best way to set a field to null using JSON in a REST call?

 

something other than this? 

         "field": null,

nmrao
Community Hero

Use groovy script to make that property null.

For example, there is a test case property say property1 with value either "null" or ""

set_null_to_property.png

 

And use ${#TestCase#test} in your REST request

NOTE: You don't need to assign value to test1 variable, you might already have it as property in DataSource step, so use that property.



Regards,
Rao.
dief123
Occasional Contributor

That is exactly how I need to set the field to null:

 "field": null

My question is how can I bring this NULL into the field from an Excel spreadsheet as a Datasource in SoapUI?

How do I specify the null in the excel spreadsheet so it fills the field variable with the  word NULL and

not "field": "NULL"?

 

nmrao
Community Hero

Have groovy script after the DataSource step.
For the first line replace it with below line, hoping that it works because never tried:
def test1 = context.expand('${DataSource#YourFieldPropertyInDataSource}')
and let the rest of the code  as it is,  shown in the earlier reply and see.

 



Regards,
Rao.
dief123
Occasional Contributor

I am not using any groovy scripts and not interested in writing any at this point.

 

All we need to do is use an Excel spreadsheet as a Datasource.  We have operational JSON and

several fields are set to variables to be populated with the values in the Excel spreadsheet.

 

My question is HOW do I enter a NULL into the Excel spreadsheet so SoapUI NG Pro inserts that

value into my JSON without quotes?

 

My JSON has "field": "${DataSource#fieldvalue}",

 

My desired outcome after the DataSource is read in and populates my JSON is:

 

"field": NULL,

 

How to I enter the NULL into the Excel spreadsheet so this works?  I have tried many variations and nothing works.

 

 

nmrao
Community Hero

Really sorry about it. Suggested what possibly could help in the case mentioned in this question. And there is nothing much effort required too as what you need is already part of the of the earlier reply.

You may ignore the above if it could not be used.

 

Do not have idea about the excel null.



Regards,
Rao.
nmrao
Community Hero

And I believe that, the one who reads the data from excel has to parse the data to the right data type. Since the way it is handled is not satisfying for you, then it is to be handled explicitly to meet the needs of the user. I am afraid that if could be handled in excel itself.


Regards,
Rao.
dief123
Occasional Contributor

I have this REST Service call ‘Spreadsheet into Composition’ that I feed with an Excel spreadsheet DataSource2.  I added the Groovy Script ‘Convert NULLS’ inline.  Below is the Groovy Script.

 

 

 “Convert NULLS – Groovy Script”

def dataSource2GlobalPartnerSBCId = context.expand( '${#TestCase#DataSource2#GlobalPartnerSBCId}' )

def globalPartnerSBCId = context.expand( '${#TestCase#GlobalPartnerSBCId}' )

def nullValue

if ("null" == dataSource2GlobalPartnerSBCId || !dataSource2GlobalPartnerSBCId) {

                              context.testCase.setPropertyValue ('globalPartnerSBCId', nullValue)

}

log.info context.testCase.getPropertyValue('globalPartnerSBCId')

 

Can you tell me why the field ‘'globalPartnerSBCId'’ in my JSON is not getting set properly to NULL?

JSON:  the excel spreadsheet has a value = NULL.

{"SBCCommunicationDetails": [{

   "CompassionSBCId": "C0028902042",

   "GlobalPartnerSBCId": "NULL",

   "SourceSystem": "SDL",

cancel
Showing results for 
Search instead for 
Did you mean: