Skip to content

Instantly share code, notes, and snippets.

View koladilip's full-sized avatar

Dilip Kola koladilip

View GitHub Profile
@koladilip
koladilip / from-to-same.json
Created August 23, 2024 12:41
From and to are same in mappings
{"code":"[{\n \"from\": \"$.event\",\n \"to\": \"$.event\"\n}]","data":"{\n \"event\": \"abc\"\n}","bindings":"const bindings = {\n \"description\": \"Enter your bindings here\"\n };","result":{"output":{"event":"abc"}},"type":"Mappings","name":""}
@koladilip
koladilip / hyphens.json
Created August 23, 2024 10:28
example with - in mappings
{"code":"[\n {\n \"to\": \"$.'content-type'\",\n \"from\": \"'application/json'\"\n }\n]","data":"{}","bindings":"const bindings = {\n \"description\": \"Enter your bindings here\"\n };","result":{"output":{"content-type":"application/json"}},"type":"Mappings","name":""}
@koladilip
koladilip / sample_mappings.json
Created August 13, 2024 12:22
sample mappings
{"code":"[\n {\n \"to\": \"$.events[0].params.item_list_id\",\n \"from\": \"$.properties.list_id\"\n },\n {\n \"to\": \"$.events[0].params.item_list_name\",\n \"from\": \"$.properties.category\"\n },\n\n {\n \"to\": \"$.events[0].params.items[*].item_name_2\",\n \"from\": \"$.properties.products[*].name\"\n },\n {\n \"to\": \"$.events[0].params.items[*].coupon\",\n \"from\": \"$.properties.products[*].coupon\"\n },\n {\n \"to\": \"$.events[0].params.items[*].price\",\n \"from\": \"$.properties.products[*].price\"\n },\n {\n \"to\": \"$.events[0].params.items[*].position\",\n \"from\": \"$.properties.products[*].position\"\n },\n {\n \"to\": \"$.events[0].params.items[*].quantity\",\n \"from\": \"$.properties.products[*].quantity\"\n },\n {\n \"to\": \"$.events[0].params.items[*].affiliation\",\n \"from\": \"$.properties.products[*].affiliation\"\n },\n
@koladilip
koladilip / invalid_array_index_mappings.json
Created July 16, 2024 16:29
invalid_array_index_mappings.json
{"code":"[\n {\n \"from\": \"$.products[*].a\",\n \"to\": \"$.items[*].a\"\n },\n {\n \"from\": \"$.products[*].b\",\n \"to\": \"$.items[0].b\"\n }\n]\n","data":"{\n \"type\": \"track\",\n \"event\": \"Checkout Step Completed\",\n \"userId\": \"joh@doe\",\n \"anonymousId\": \"anonymous@john@doe\",\n \"context\": {\n \"traits\": {\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"name\": \"John Doe\",\n \"age\": 30,\n \"email\": \"john_doe@gmail.com\",\n \"phone\": 7832377652,\n \"address\": {\n \"city\": \"Brooklyn\",\n \"country\": \"US\",\n \"postalCode\": \"10001\",\n \"state\": \"NY\",\n \"street\": \"51st Avenue\"\n },\n \"company\": {\n \"name\": \"RudderStack\",\n \"id\": 18,\n \"industry\": \"SaaS\",\n \"employee_count\": 130,\n
{"code":"^.orders@order.products@product.({\n product_name: product.name\n })[]","data":"{\n \"orders\": [\n {\n \"products\": [\n {\n \"name\": \"Smartphone\"\n }\n ]\n },\n {\n \"products\": [\n {\n \"name\": \"Laptop\"\n },\n {\n \"name\": \"Headphones\"\n }\n ]\n }\n ]\n }","bindings":"const bindings = {\n \"description\": \"Enter your bindings here\"\n };","result":{"output":[{"product_name":"Smartphone"},{"product_name":"Laptop"},{"product_name":"Headphones"}]},"type":"JsonTemplate","name":""}
{"code":"^.orders@order.products@product.({\n product_name: product.name\n })[]","data":"{\n \"orders\": [\n {\n \"products\": [\n {\n \"name\": \"Smartphone\"\n }\n ]\n },\n {\n \"products\": []\n }\n ]\n }","bindings":"const bindings = {\n \"description\": \"Enter your bindings here\"\n };","result":{"output":[{"product_name":"Smartphone"}]},"type":"JsonTemplate","name":""}
@koladilip
koladilip / all_features.json
Last active June 18, 2024 02:44
All Custom Mappings
{"code":"[\n {\n \"input\": \"$.userId\",\n \"output\": \"$.user.id\"\n },\n {\n \"input\": \"$.discount\",\n \"output\": \"$.events[0].items[*].discount\"\n },\n {\n \"input\": \"$.products[?(@.category)].id\",\n \"output\": \"$.events[0].items[*].product_id\"\n },\n {\n \"input\": \"$.events[0]\",\n \"output\": \"$.events[0].name\"\n },\n {\n \"input\": \"$.products[?(@.category)].name\",\n \"output\": \"$.events[0].items[*].product_name\"\n },\n {\n \"input\": \"$.products[?(@.category)].category\",\n \"output\": \"$.events[0].items[*].product_category\"\n },\n {\n \"input\": \"$.products[?(@.category)].variations[*].size\",\n \"output\": \"$.events[0].items[*].options[*].s\"\n },\n {\n \"input\": \"$.products[?(@.category)].(@.price * @.quantity * (1 - $.discount / 100))\",\n \"output\": \"$.events[0].items[*].value\"\n },\n {\n \"input\": \"$.products[?(@.category)].(@.price * @.quantity * (1 - $.discount / 100)).sum()\",\n \"output\"
@koladilip
koladilip / mappings-example.json
Created June 14, 2024 06:16
Json Template Engine Mappings Example
{"code":"[\n {\n \"description\": \"Copies properties of a to root level in the output\",\n \"input\": \"$.a\",\n \"output\": \"$\"\n },\n {\n \"description\": \"Combines first and last name in the output\",\n \"input\": \"$.b[*].(@.firstName + ' ' + @.lastName)\",\n \"output\": \"$.items[*].name\"\n }\n]","name":"simple-example","type":"Mappings","data":"{\n \"a\": {\n \"foo\": 1,\n \"bar\": 2\n },\n \"b\": [\n {\n \"firstName\": \"foo\",\n \"lastName\": \"bar\"\n },\n {\n \"firstName\": \"fizz\",\n \"lastName\": \"buzz\"\n }\n ]\n}","bindings":"const bindings = {\n \"description\": \"Enter your bindings here\"\n };"}
@koladilip
koladilip / extract-employee-names.js
Created March 22, 2024 03:53
Extracts Employee Names
function(___d) {
let ___r;
let ___1;
let ___2;
let ___3;
let ___4;
let ___5;
let ___6;
let ___7;
let ___8;
@koladilip
koladilip / descendant-operator.json
Created March 21, 2024 18:51
Example demonstrate the descendant operator (..):
{"code":".employees..name","name":"descendant-operator","type":"JsonTemplate","data":"{\n \"employees\": [\n {\n \"id\": 1,\n \"name\": \"John\",\n \"department\": \"Sales\",\n \"subordinates\": [\n {\n \"id\": 2,\n \"name\": \"Alice\",\n \"department\": \"Marketing\"\n },\n {\n \"id\": 3,\n \"name\": \"Bob\",\n \"department\": \"Sales\"\n }\n ]\n },\n {\n \"id\": 4,\n \"name\": \"Emily\",\n \"department\": \"HR\",\n \"subordinates\": [\n {\n \"id\": 5,\n \"name\": \"Charlie\",\n \"department\": \"HR\"\n },\n {\n \"id\": 6,\n \"name\": \"David\",\n \"department\": \"Finance\"\n }\n ]\n }\n ]\n}\n","bindings":"const bindings = {\n \"description\": \"Enter your bindings here\"\n };"}