Forum Discussion

waynemmn's avatar
waynemmn
Contributor
9 years ago
Solved

JSON Path expression not working on project I updated to 1.6.0

Hello, 

I have a JSONPath Expression that worked just fine in SoapUI NG 1.3.1 but today I updated to 1.6.0 and now it fails. 

 

My RAW JSON looks like this. 

 


{
"action" : "get",
"status" : "200",
"entities" : [ {
"uuid" : "dc0bddc2-e087-11e5-bc95-fa163e55f738",
"type" : "online-transaction",
"created" : 1456930982163,
"modified" : 1456930982163,
"alias" : "20160302^960^960438^103730",
"transient" : false,
"base-type" : "transaction",
"begin-date" : "1456898400000",
"end-date" : "1456898400000",
"metadata" : {
"path" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/purchases/dc0bddc2-e087-11e5-bc95-fa163e55f738",
"connections" : {
"contains" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/purchases/dc0bddc2-e087-11e5-bc95-fa163e55f738/contains"
},
"connecting" : {
"purchases" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/purchases/dc0bddc2-e087-11e5-bc95-fa163e55f738/connecting/purchases"
}
},
"name" : "20160302^960^960438^103730",
"net-total" : 1669.97,
"order-number" : "BBY01-732324000071",
"reg-transaction-id" : 103730,
"sale-type" : "1",
"sales-tax" : 121.48,
"store-id" : 960,
"tags" : "transaction:20160302^960^960438^103730",
"workstation-id" : 960438
}, {
"uuid" : "dd44ac05-e087-11e5-bc95-fa163e55f738",
"type" : "online-transaction",
"created" : 1456930984213,
"modified" : 1456930984213,
"alias" : "20160302^960^960438^104407",
"transient" : false,
"base-type" : "transaction",
"begin-date" : "1456898400000",
"end-date" : "1456898400000",
"metadata" : {
"path" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/purchases/dd44ac05-e087-11e5-bc95-fa163e55f738",
"connections" : {
"contains" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/purchases/dd44ac05-e087-11e5-bc95-fa163e55f738/contains"
},
"connecting" : {
"purchases" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/purchases/dd44ac05-e087-11e5-bc95-fa163e55f738/connecting/purchases"
}
},
"name" : "20160302^960^960438^104407",
"net-total" : 1669.97,
"order-number" : "BBY01-732324000071",
"reg-transaction-id" : 104407,
"sale-type" : "1",
"sales-tax" : 121.48,
"store-id" : 960,
"tags" : "transaction:20160302^960^960438^104407",
"workstation-id" : 960438
} ],
"first" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/connections/purchases/online-transaction?limit=10",
"last" : "/loyaltyaccounts/dc47d560-e087-11e5-bc95-fa163e55f738/connections/purchases/online-transaction?limit=10&last=true",
"next" : "",
"prev" : ""
}

 

Note the multiple entities. 

 

My JSONPath Expression looks like this. 

 

 

$.entities[?(@.alias==${Groovy Script#result})].alias.[0]

 

The expected result is : ${Groovy Script#result}

 

the value of ${Groovy Script#result} is "20160302^960^960438^103730"

 

Error Message received: 

$.entities[?(@.alias==${Groovy Script#result})].alias.[0] : InvalidPathException:java.long.StringIndexOutOfBoundsException: String index out of range: 57

Why does this work in 1.3.1 and not here?

Do you have any brilliant wisdom as to how to fix this?

 

Thank you. 

  • We upgraded our JSON Path library, and it turned out that its developers decided the syntax you use here had been a bug in older releases. As they put it, "The problem is that from a JSONPath perspective it does not make sense. The last part [0] does not correspond to a path in the document." I guess they mean that the "alias" tag here is a leaf in the document tree, and you should not use array indices after leaves.

     

    Nevertheless, we partially restored the old behavior in Ready! API 1.5.0 (and 1.6.0, of course), but for now you should use your JSON Path without the dot before [0]:

     

    $.entities[?(@.alias==${Groovy Script#result})].alias[0]

5 Replies

  • AntonE's avatar
    AntonE
    SmartBear Alumni (Retired)

    We upgraded our JSON Path library, and it turned out that its developers decided the syntax you use here had been a bug in older releases. As they put it, "The problem is that from a JSONPath perspective it does not make sense. The last part [0] does not correspond to a path in the document." I guess they mean that the "alias" tag here is a leaf in the document tree, and you should not use array indices after leaves.

     

    Nevertheless, we partially restored the old behavior in Ready! API 1.5.0 (and 1.6.0, of course), but for now you should use your JSON Path without the dot before [0]:

     

    $.entities[?(@.alias==${Groovy Script#result})].alias[0]