Forum Discussion

rcummings's avatar
rcummings
New Contributor
4 years ago

Datasource JSONPath Array Not Returning Data

My JSON datasource has the following structure:

{
"name" : "test",
"customerId" : "123",
"contracts" : [
{
"url" : "http://1231"
},
{
"url" : "http://1232"
},
{
"url" : "http://1233"
}
]
}

 

I can extract name and customerId using Column Paths = name and customerId, but when I try to extract the whole array for contracts, I get nothing.  I can access each url entry using contracts[0].url, but anything like contracts[0:]url or contracts[*].url is failing.  How can I get the whole array?

  • richie's avatar
    richie
    Community Hero

    Hey rcummings 

     

    I'm on my phone so i cant double check by reproducing your issue, and it's been awhile since I bothered using a json data source, but the jsonpath to the contracts array is simply $.contracts - i.e. without any array indicator (e.g. [])

     

    have you tried using just $.contracts ??

     

    nice one,

     

    Rich

    • rcummings's avatar
      rcummings
      New Contributor

      Thank you...

       

      When I use "contracts", I get the first entry only when there is just a single element in the array, "[]" if the array is empty and for records with multiple elements in the array I get nothing.

       

      If I use contracts[*].url, I get nothing for any records.

       

      If I use contracts[0].url, I get the first element for records that have elements.  And I can use other integers to access other elements.  But I can't get all of them.

      • richie's avatar
        richie
        Community Hero
        Hi rcummings,

        Im bit busy today (moving house) so cant reproduce today, however, ive just remembered when i was using the json datasource a couple of years ago i always had problems. It seemed a little flakey and struggled to get it to work and dont know if the functionality has changed.

        I could be wrong, but i think i got around the problems by using the xml datasource but switched the type to jsonpath within the xml datasource. This worked for me.

        Can you try the xml datsource but changing the type?

        I will get to looking at it tomorrow, but wanted to respond with this possible workaround whilst youre waiting.

        Cheers,

        Rich
    • rcummings's avatar
      rcummings
      New Contributor

      I tried various combinations and I am not seeing it work.  I started to use a groovy script as the data source and it had no problem with the structure.  

      • richie's avatar
        richie
        Community Hero
        Hey rcummings,

        I'll be able to try and reproduce over the weekend. Sorry. I totally forgot about your issue.

        Ta

        Rich