spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

Incorrect result when using filters inside a deeply nested JSON #64

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. If this is the JSON under consideration: 
{"storeFronts":[{"storeFrontId":{"storeUUID":"F2AC45A479F04796A584DD9FCE751842"}
,"offerFulfillmentOptionWrappers":[{"offerShippingMethodWrappers":[{"shipMethod"
:"VALUE"},{"shipMethod":"STANDARD"},{"shipMethod":"RUSH"}],"availabilityStatus":
"AVAILABLE","fulfillmentOption":"S2H","availableQuantity":44}],"isStorePUTEligib
le":false,"canAddToCart":true,"storeFrontType":"ONLINE"}],"offer":{"tenantId":0,
"startDate":946684800000,"offerRank":0,"marketOfferCrossReferences":[{"subsystem
Name":"CATALOG","identifierName":"ITEM_ID","US_WMT_DOTCOM_ITEM_ID":"872852","US_
WMT_DOTCOM_SELLER_ID":"0"}],"endDate":2840054400000,"offerLifecycleStatus":"ACTI
VE","productId":{"wupc":"0004271425050","USItemId":872852,"gtin":"00042714250500
","upc":"042714250500","productId":"3SGJKT8FH5K6"},"offerAttributes":{"Return 
Thru WM":{"groupName":"Additional 
Specifications","valueRank":0,"valueSource":"Walmart.com","isMultiValued":false,
"name":"Return Thru WM","value":"No","type":"STRING"},"Return 
Option":{"groupName":"Additional 
Specifications","valueRank":0,"valueSource":"Walmart.com","isMultiValued":false,
"name":"Return 
Option","value":"1","type":"STRING"},"wm_item_num":{"valueRank":0,"isMultiValued
":false,"name":"wm_item_num","value":"003071216","type":"STRING"},"max_item_coun
t_per_order":{"valueRank":0,"isMultiValued":false,"name":"max_item_count_per_ord
er","value":"200","type":"STRING"},"is_care_plan_eligible":{"valueRank":0,"isMul
tiValued":false,"name":"is_care_plan_eligible","value":"N","type":"STRING"}},"se
llerOfferId":"872852","globalTaxCode":"2038356","offerType":"ONLINE_AND_STORE","
offerIdentifiers":{"GTIN":"00042714250500","WUPC":"0004271425050","UPC":"0427142
50500"},"sellerId":"455A2F43226F41319399794332C71B7F","complianceAttributes":{"U
S":{"locationName":"US","attributes":[{"valueRank":0,"isMultiValued":false,"name
":"origin_of_assembly","value":"Imported","type":"STRING"},{"valueRank":0,"isMul
tiValued":false,"name":"origin_of_components","value":"Imported","type":"STRING"
},{"valueRank":0,"isMultiValued":false,"name":"nonspillable_battery_ind","value"
:"N","type":"STRING"},{"valueRank":0,"values":[{"valueRank":0,"value":"Hand 
Wash"},{"valueRank":0,"value":"Line 
Dry"}],"isMultiValued":true,"name":"fabric_care_instructions","value":"Hand 
Wash","type":"STRING"}]}},"streetDateDisplayable":true,"crossBorderTradeAttribut
es":{"isEligible":false},"offerLogistics":{"productShipPackageMeasuresList":[{"p
roductWeight":{"unitOfMeasure":"LB","measurementValue":0.2},"productDimensions":
{"productWidth":{"unitOfMeasure":"IN","measurementValue":9.47},"productHeight":{
"unitOfMeasure":"IN","measurementValue":1.82},"productLength":{"unitOfMeasure":"
IN","measurementValue":8.62}},"packageNumber":0}],"perishable":false,"shipAsIs":
false,"numberOfBoxes":1,"hazardMaterial":false,"airShippable":true,"ormd":false}
,"offerPublishStatus":"PUBLISHED","offerId":{"USItemId":872852,"wupc":"000427142
5050","gtin":"00042714250500","USSellerId":0,"upc":"042714250500","offerId":"FD9
13EBE5FF54EC681A3D6A0DBC61568"},"originOfAssembly":[{"locationType":null,"locati
onId":null,"locationName":"Imported"}],"marketAttributes":{"show_button_in":{"va
lueRank":0,"isMultiValued":false,"name":"show_button_in","value":"11","type":"ST
RING"},"pch_id":{"valueRank":0,"isMultiValued":false,"name":"pch_id","value":"40
11176","type":"STRING"},"wm_dept_num":{"valueRank":0,"isMultiValued":false,"name
":"wm_dept_num","value":"30","type":"STRING"},"rh_path":{"valueRank":0,"isMultiV
alued":false,"name":"rh_path","value":"7042:7049:4652:8782:8785","type":"STRING"
},"pcp_seller_id":{"valueRank":0,"isMultiValued":false,"name":"pcp_seller_id","v
alue":"0","type":"STRING"},"primary_shelf_id":{"valueRank":0,"isMultiValued":fal
se,"name":"primary_shelf_id","value":"1078025","type":"STRING"},"primary_categor
y_path":{"valueRank":0,"isMultiValued":false,"name":"primary_category_path","val
ue":"0:5438:1078024:1078025","type":"STRING"},"item_class_id":{"valueRank":0,"is
MultiValued":false,"name":"item_class_id","value":"46","type":"STRING"},"alterna
te_shelves":{"valueRank":0,"values":[{"valueRank":0,"value":"136320"},{"valueRan
k":0,"value":"136329"},{"valueRank":0,"value":"579376"},{"valueRank":0,"value":"
920699"},{"valueRank":0,"value":"1078025"}],"isMultiValued":true,"name":"alterna
te_shelves","value":"136320","type":"STRING"},"display_status":{"valueRank":0,"i
sMultiValued":false,"name":"display_status","value":"PUBLISHED","type":"STRING"}
,"primary_distributor_id":{"valueRank":0,"isMultiValued":false,"name":"primary_d
istributor_id","value":"10010","type":"STRING"},"char_primary_category_path":{"v
alueRank":0,"isMultiValued":false,"name":"char_primary_category_path","value":"A
pparel/Intimates/Bras","type":"STRING"},"item_type":{"valueRank":0,"isMultiValue
d":false,"name":"item_type","value":"0","type":"STRING"}}},"seller":{"partnerNam
e":"Walmart.com","partnerDisplayName":"Walmart.com","sellerId":"455A2F43226F4131
9399794332C71B7F","sellerType":"INTERNAL","entityErrors":[],"catalogSellerId":0}
,"isOfferPUTEligible":false}

2. And we want to use the following JSONPath expression: 
"$.offer.offerId.offerId" as follows:
JsonPath.read(offerWrapper, 
"$.storeFronts[*].offerFulfillmentOptionWrappers[?(@.fulfillmentOption=\"S2H\")]
.offerShippingMethodWrappers[*].shipMethod"), where offerWrapper is the JSON 
Object given above, we get an empty list.

What is the expected output? What do you see instead?
Expected Output is ["VALUE","STANDARD","RUSH"]. What we see instead is []

What version of the product are you using? On what operating system?
Using version 1.2.0. OS is Windows 7 64 bit

Please provide any additional information below.
Looks like the filter expression is not working in a nested JSON.

Original issue reported on code.google.com by ritwick5...@gmail.com on 16 Jan 2015 at 11:43

GoogleCodeExporter commented 9 years ago
This can be closed out - figured out the solution from the filter examples in 
the tests...need to use the following...
$.storeFronts[*].offerFulfillmentOptionWrappers[?(@.fulfillmentOption=='S2H')].o
fferShippingMethodWrappers[*].shipMethod instead of 
$.storeFronts[*].offerFulfillmentOptionWrappers[?(@.fulfillmentOption 
='S2H')].offerShippingMethodWrappers[*].shipMethod...
only thing is all the following things work in the online JSONPath Expression 
Tester:
1. fulfillmentOption=='S2H'
2. fulfillmentOption='S2H'
3. fulfillmentOption="S2H"

So I thought it would work here as well...but as long as one of these are 
working, I am fine...thanks for writing this wonderful library - all my JSON 
parsing code can now be replaced with elegant one liners.

Thank you so much,
Ritwick. 

Original comment by ritwick5...@gmail.com on 17 Jan 2015 at 1:08

GoogleCodeExporter commented 9 years ago

Original comment by kalle.st...@gmail.com on 27 Jan 2015 at 11:49