Data Mapping
16 min
jsonpath data mapping guide data mapping in peach allows you to extract information from incoming event payloads (like shopify webhooks or custom api calls) and map them directly into variables, template placeholders, recipients, or deduplication keys this guide explains how to use jsonpath to map payload fields, from basic properties to complex structures and calculations 1\ mappings scopes in peach there are three main contexts where you will define data mappings in peach recipient mapping ( recipient ) purpose tells peach who should receive the message required fields typically maps a phone number (e g phone number ) and optionally a name note if peach cannot resolve the recipient's phone number, the automation will silently fail to send template variables ( variable ) purpose provides the dynamic content required by your whatsapp template placeholders (e g , {{1}} , {{2}} or named keys) usage maps keys like customer name or order id to their values in the webhook payload deduplication key ( dedup key ) purpose prevents duplicate messages from being sent if the source system sends the same event multiple times usage maps to a unique transaction id (e g $ order id or $ checkout token ) 2\ basic jsonpath syntax jsonpath is like xpath or css selectors, but for json objects all jsonpaths in peach must start with $ (which refers to the root of the event payload) static values (no $ prefix) if a value doesn't start with $ , peach treats it as a static string fallback example mapping first name to valued customer will always output "valued customer" regardless of the payload direct path matching payload { "customer" { "first name" "alice", "phone" "+1234567890" } } mapping $ customer first name > resolves to "alice" mapping $ customer phone > resolves to "+1234567890" 3\ peach specific features & smart defaults peach has built in smarts to make mapping easier and more resilient subscriber & contact interchangeability peach automatically maps subscriber and contact as aliases if your payload has a contact object but you write $ subscriber name , it resolves correctly likewise, if your payload has a subscriber object and you write $ contact name , it also resolves correctly recursive / deep scanning ( $ ) if you don't know the exact path of a field, or if it can appear at different levels of the json structure, use $ to search recursively payload { "customer" { "default address" { "phone" "+1999999999" } } } mapping $ phone resolves to "+1999999999" (peach finds the first non nil match in the object structure) 4\ working with lists (arrays) if your payload contains lists of items (e g , order line items), you can extract items or count them extracting a specific item (index subscript) use \[0] to get the first item in a list (indexing starts at 0 ) payload { "items" \[ { "title" "blue t shirt" }, { "title" "red socks" } ] } mapping $ items\[0] title > resolves to "blue t shirt" joining multiple items use \[ ] to select all items if multiple matches are found, peach automatically joins them with a comma mapping $ items\[ ] title resolves to "blue t shirt, red socks" array length / count helpers peach supports length , size , and count helpers directly at the end of your jsonpath mapping $ items length (or $ items size , $ items count ) resolves to 2 (returns the count of items in the list) 5\ structured json mapping (fenced json blocks) sometimes, you need to map complex parameters (like media file attachments with customized headers) you can provide structured json wrapped in markdown style code fences ```json ``` peach will parse the json block and resolve any internal values starting with $ dynamically example media headers when sending a document or image template, you might need to map both the url and the filename dynamically value input ```json { "link" "$ data invoice pdf url", "filename" "$ data invoice display name" } payload { "data" { "invoice" { "pdf url" "https //example com/inv 102 pdf", "display name" "invoice august pdf" } } } resulting output { "link" "https //example com/inv 102 pdf", "filename" "invoice august pdf" } 6\ common recipes & examples setup a notification (shopify order paid) when setting up a stream trigger on a shopify order paid event, use these common mappings recipient phone $ customer phone or $ customer default address phone (or $ phone for safety) deduplication key $ id (using the order id to prevent double processing) template variable (customer name) $ customer first name template variable (item summary) $ line items\[ ] title template variable (item count) $ line items length
