Replies: 1 comment 1 reply
-
Just move the function definition outside the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm new to this library and am trying to write functions that are reusable.
Here's a sample template I'm trying to use but getting a parse error.
{ def map_status(status) if ($status == 0) "ACTIVE" else if ($status == 1) "INACTIVE" else "UNDEFINED" "customer_id": sha256-hex(.customer_id), "customer_status_code": map_status(.customer_status), "locations": [ { "zip_code": .invoice_address_zip_code, "city": .invoice_address_city }, { "zip_code": .delivery_address_zip_code, "city": .delivery_address_city } ], "customer_type": .attributes.customer_type, "customer_class": .attributes.customer_class, "producer_team": "us.california.burbank.disney" }
Sample Json:
{ "customer_id": 123456, "customer_status": 2, "invoice_address_street": "McDuck Manor", "invoice_address_zip_code": "1312", "invoice_address_city": "Duckburg", "delivery_address_street": "Webfoot Walk", "delivery_address_zip_code": "1313", "delivery_address_city": "Duckburg", "attributes": { "customer_type": "C2C", "customer_class": "A", "last_order": "2022-03-10T18:25:43.511Z" } }
Error:
com.schibsted.spt.data.jslt.JsltException: Parse error: Encountered " "def" "def "" at line 2, column 3. Was expecting: "for" ... at <inline>:1:1 at com.schibsted.spt.data.jslt.parser.ParserImpl.compileExpression(ParserImpl.java:62) at com.schibsted.spt.data.jslt.Parser.compile(Parser.java:226) at com.schibsted.spt.data.jslt.Parser.compileString(Parser.java:86) at com.schibsted.spt.data.jslt.Parser.compileString(Parser.java:74) at no.priv.garshol.jslt.playground.PlaygroundServer$JsltHandler.handle(PlaygroundServer.java:54) at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:59) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:516) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) at java.base/java.lang.Thread.run(Thread.java:829)
I appreciate your response on this :)
Beta Was this translation helpful? Give feedback.
All reactions