IBM / JSONata4Java

Open Source Java version of JSONata
Apache License 2.0
89 stars 37 forks source link

Support object construction as part of the path expression #43

Open wnm3 opened 4 years ago

wnm3 commented 4 years ago

Account.Order{OrderID: Product."Product Name"} object-constructor:case008 Account.Order.{OrderID: Product."Product Name"} object-constructor:case009 Account.Order.Product{$string(ProductID): Price} object-constructor:case010 Account.Order.Product{$string(ProductID): (Price)[0]} object-constructor:case011 Account.Order.Product.{$string(ProductID): Price} object-constructor:case012 Account.Order.Product{ProductID: "Product Name"} object-constructor:case013 Account.Order.Product.{ProductID: \"Product Name\"} object-constructor:case014 Account.Order{OrderID: $sum(Product.(PriceQuantity))} object-constructor:case015 Account.Order.{OrderID: $sum(Product.(PriceQuantity))} object-constructor:case016 Account.Order.Product{$.\"Product Name\": Price, $.\"Product Name\": Price} object-constructor:case017 Account.Order.Product{Product Name: Price, SKU: Price} object-constructor:case018 Account.Order{ OrderID: { "TotalPrice":$sum(Product.(Price Quantity)), "Items": Product."Product Name" }} object-constructor:case019 { "Order": Account.Order.{ "ID": OrderID, "Product": Product.{ "Name": $."Product Name", "SKU": ProductID, "Details": { "Weight": Description.Weight, "Dimensions": Description.(Width & " x " & Height & " x " & Depth) } }, "Total Price": $sum(Product.(Price Quantity)) }} object-constructor:case020 Phone{type: $join(number, ", "), "phone":number} object-constructor:case022 case025.jsonata object-constructor:case025

We need to expect an object construction as part of the path.

wnm3 commented 4 years ago

[ERROR] case010(object-constructor) Time elapsed: 0.007 s <<< FAILURE! java.lang.AssertionError: expected:<{"345664":107.99,"858236":21.67,"858383":[34.45,34.45]}> but was:<[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1},{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]>

[ERROR] case011(object-constructor) Time elapsed: 0.001 s <<< FAILURE! java.lang.AssertionError: expected:<{"345664":107.99,"858236":21.67,"858383":34.45}> but was:<[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1},{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]>

[ERROR] case016(object-constructor) Time elapsed: 0.002 s <<< FAILURE! java.lang.AssertionError: expected:<[{"order103":90.57000000000001},{"order104":245.79000000000002}]> but was:<[{"OrderID":"order103","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1}]},{"OrderID":"order104","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]}]>

[ERROR] case017(object-constructor) Time elapsed: 0.005 s <<< FAILURE! java.lang.AssertionError: expected: but was:<[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1},{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]>

[ERROR] case018(object-constructor) Time elapsed: 0.002 s <<< FAILURE! java.lang.AssertionError: expected:<{"Bowler Hat":[34.45,34.45],"0406654608":34.45,"Trilby hat":21.67,"0406634348":21.67,"040657863":34.45,"Cloak":107.99,"0406654603":107.99}> but was:<[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1},{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]>

[ERROR] case022(object-constructor) Time elapsed: 0.001 s <<< FAILURE! java.lang.AssertionError: expected:<{"home":"0203 544 1234","phone":["0203 544 1234","01962 001234","01962 001235","077 7700 1234"],"office":"01962 001234, 01962 001235","mobile":"077 7700 1234"}> but was:<[{"type":"home","number":"0203 544 1234"},{"type":"office","number":"01962 001234"},{"type":"office","number":"01962 001235"},{"type":"mobile","number":"077 7700 1234"}]>

[ERROR] case014(object-constructor) Time elapsed: 0.001 s <<< FAILURE! java.lang.AssertionError: expected: but was:<[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1},{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]>

[ERROR] case015(object-constructor) Time elapsed: 0.002 s <<< FAILURE! java.lang.AssertionError: expected:<{"order103":90.57000000000001,"order104":245.79000000000002}> but was:<[{"OrderID":"order103","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1}]},{"OrderID":"order104","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]}]>

[ERROR] case019(object-constructor) Time elapsed: 0.001 s <<< FAILURE! java.lang.AssertionError: expected:<{"order103":{"TotalPrice":90.57000000000001,"Items":["Bowler Hat","Trilby hat"]},"order104":{"TotalPrice":245.79000000000002,"Items":["Bowler Hat","Cloak"]}}> but was:<[{"OrderID":"order103","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1}]},{"OrderID":"order104","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]}]>

[ERROR] case012(object-constructor) Time elapsed: 0.001 s <<< FAILURE! java.lang.AssertionError: expected:<[{"858383":34.45},{"858236":21.67},{"858383":34.45},{"345664":107.99}]> but was:<[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1},{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]>

[ERROR] case008(object-constructor) Time elapsed: 0.002 s <<< FAILURE! java.lang.AssertionError: expected:<{"order103":["Bowler Hat","Trilby hat"],"order104":["Bowler Hat","Cloak"]}> but was:<[{"OrderID":"order103","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1}]},{"OrderID":"order104","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]}]>

[ERROR] case025(object-constructor) Time elapsed: 0.001 s <<< ERROR! com.api.jsonata4java.expressions.ParseException: line 1:15 at null: token recognition error at: 'λ' , line 1:19 at [@6,19:19=',',<10>,1:19]: mismatched input ',' expecting {';', ')'}

[ERROR] case009(object-constructor) Time elapsed: 0.002 s <<< FAILURE! java.lang.AssertionError: expected:<[{"order103":["Bowler Hat","Trilby hat"]},{"order104":["Bowler Hat","Cloak"]}]> but was:<[{"OrderID":"order103","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1}]},{"OrderID":"order104","Product":[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]}]>

[ERROR] case013(object-constructor) Time elapsed: 0.002 s <<< FAILURE! java.lang.AssertionError: expected: but was:<[{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"0406654608","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":2},{"Product Name":"Trilby hat","ProductID":858236,"SKU":"0406634348","Description":{"Colour":"Orange","Width":300,"Height":200,"Depth":210,"Weight":0.6},"Price":21.67,"Quantity":1},{"Product Name":"Bowler Hat","ProductID":858383,"SKU":"040657863","Description":{"Colour":"Purple","Width":300,"Height":200,"Depth":210,"Weight":0.75},"Price":34.45,"Quantity":4},{"ProductID":345664,"SKU":"0406654603","Product Name":"Cloak","Description":{"Colour":"Black","Width":30,"Height":20,"Depth":210,"Weight":2},"Price":107.99,"Quantity":1}]>

wnm3 commented 4 years ago

flattening:case040 flattening:case041