Back to LinkedIn posts

LinkedIn post 352

๐Ÿงช๐Ÿ’ง How would you extract a substring from another string in a formula/flow?

๐Ÿงช๐Ÿ’ง How would you extract a substring from another string in a formula/flow?

For example, let's say you have a JSON (you probably shouldn't have one but this is a contrived example) that you need to extract a certain field in the middle of it.
You want to extract the email address from below:
๐Ÿ‘‰๐Ÿผ originalString: {"id":"123","emailAddress":"no@no.com","governmentID":"123456789"}

Simple example and suggested formula:
๐Ÿ‘‰๐Ÿผ MID( originalString, FIND( beginningDelimiter, originalString ) + sizeOfBeginningDelimiter, FIND( endingDelimiter, originalString ) - FIND( beginningDelimiter, originalString ) - sizeOfBeginningDelimiter )

๐Ÿ‘‰๐Ÿผ beginingDelimiter: "emailAddress":"
๐Ÿ‘‰๐Ÿผ endingDelimiter: ","governmentID
๐Ÿ‘‰๐Ÿผ sizeOfBeginningDelimiter: 16 (from "emailAddress":")

See example in the screenshot (using formulon.io to more quickly test formulas)

PS.: It is better to not rely on the JSON being always in the same format (someone may add another fields or change the order of fields) and use Apex instead of formula.
However, I've seen clients being adamant about not using any Apex whatsoever (and this policy was from their IT - incredibly!).

graphical user interface, text, application, email