The shop's order reshaped for the warehouse. jsonpath reads single values out of the order, jq builds the pick list the warehouse wants: only the sku and the quantity of each line.
INFO ... json-transform.camel.yaml:25 : Order ORD-1001 with 2 lines: {"orderId": "ORD-1001", "customer": "C-482", ...} INFO ... json-transform.camel.yaml:32 : Pick list for the warehouse: { "order" : "ORD-1001", "country" : "DK", "pick" : [ { "sku" : "CAMEL-TSHIRT", "qty" : 2 }, { "sku" : "CAMEL-MUG", "qty" : 1 } ] }
Install JBang and the Camel CLI as described in the root README; camel --version confirms the install.
camel run *
order.json; resource:file: in a constant expression loads a file as the body.jsonpath expressions pick the order id and the number of lines into headers.transform with a jq expression builds a new document from the old one: .orderId becomes order, and [.lines[] | {sku, qty}] keeps two fields of every line.order.json and logs it.jsonpath: $.orderId and log it.jsonpath: $.lines.length().transform step with a jq expression that keeps only the order id, and log the result.total: ([.lines[].qty] | add) in the jq expression.[.lines[] | select(.qty > 1)].The example comes with a test in the Citrus YAML DSL, test/json-transform.citrus.it.yaml, which the Camel CLI runs:
camel test run test/json-transform.citrus.it.yaml
The test starts the route and verifies that the pick list is logged.
If you hit any problem using Camel or have some feedback, then please let us know.
We also love contributors, so get involved :-)
The Camel riders!