Forum Discussion

nkasemsan's avatar
nkasemsan
Occasional Contributor
8 years ago

Property transfer return empty array in JSON response

Hello, 

 

I have a test step that returns a JSON response (sample response attached).  In a subsequent step, I do a property transfer in which a take the first element in the response and, in the Telecoms node, I want to grab the first element in the Telecoms array where the 'SystemCode = 'email' .  

 

I know this is not correct because when I use a JSON online evaluator, it will return ALL elements where SystemCode ='email' --all 25--, not just the first one it finds. 

 

$..Telecoms[?(@.SystemCode=="email")].ValueString

 

Moreover, when I run the testSuite and I look at what is returned in the Email property transfer, it returns and empty array (screenshots attached).

 

My questions are:

 

1.  What is the correct format for the Source in the property transfer so that I only get the first element in the JSON Response, and within the Telecoms node of that element, I get the first element where 'SystemCode = 'email'

 

2.  If I can't do this in a Property Transfer step, what is the best way to accomplish this?

 

2.  Am I seeing an empty array in the results email property transfer because there a limitation i in terms of the number of elements it can return in an array, and if the response returns more than it can handle, it returns an empty response?  

  • Would you believe that a property transfer only works with single quotes in the source JSONPath expression $..Telecoms[?(@.SystemCode=='phone')].ValueString

     

    JSONPath match assertions also work with single not double quotes. That seems like a defect.

     

    To get the first element where 'SystemCode = 'email' try

    $..Telecoms[?(@.SystemCode=='email')][0].ValueString

  • PaulMS's avatar
    PaulMS
    Super Contributor

    Would you believe that a property transfer only works with single quotes in the source JSONPath expression $..Telecoms[?(@.SystemCode=='phone')].ValueString

     

    JSONPath match assertions also work with single not double quotes. That seems like a defect.

     

    To get the first element where 'SystemCode = 'email' try

    $..Telecoms[?(@.SystemCode=='email')][0].ValueString

    • nkasemsan's avatar
      nkasemsan
      Occasional Contributor

      That is the perfect solution.  After I changed it to single quotes and added[0] at the end, I got the first phone element.  Thank you very much for the suggestion!