Handlebars to remove new line and return text in between characters
Hi Good Afternoon,
I am currently running into an issue while trying to remove the json formatting to remove the new line symbol and extract data between text. I am successfully able to extract the information using this handlebar "{{split (split note "IndustryType:" 1) "IfOTHERdescribe:" 0}}" and I am successfully able to remove the new line "\n" using this handlebar "{{replace (jsonEncode [note])"\n" ", "}}" but when I attempt to combine them such as "{{{replace (split (split note "IndustryType:" 1) "IfOTHERdescribe:" 0)(jsonEncode [note])"\n" ", "}}}" or this "{{replace (jsonEncode [note])"\n" ", "(split (split note "IndustryType:" 1) "IfOTHERdescribe:" 0)}}" it either does one or the other and not both. The text and formatting of the text being
"note": "CompanyName: Placeholder\nPosition: None\ntext-ZIED: None\nFederalTaxID: None\nResaleTaxCertificateNo: None\nResaleTaxCertificate: None\nSecondaryPhone: None\nFax: None\nLocksmithLicenseNumber: None\nIndustryType: Contractor\nIfOTHERdescribe: None\nAreYouDahuaDealer: False\nSalesContactDahuaDealer: False\nProductCategories: None\nYearsinBusiness: 0\nNumberofLocksmiths: 0\nDoyouhaveastorefront: None\nNoOfLocations: None\nAnnualSales: None\nNumberofVehicles: None\nPrimarySupplier: None\nSecondarySupplier: None\nHowdidyoufindus: None\nAgreeToTerms: True",
Comments
Shadner Joseph will this work for you?
Additionally, if the fields and value pairs aren't always in the same position, you may need a script to convert the string to JSON. Here is a sample transform below:
Thank You!
The solution below was exactly what I needed!
Tyler Lamparter,
How come the following expression with the following input returns nothing when the next input returns '123456' correctly?
Returns Nothing:
Returns 123456:
Jared Fraley it's easier to visualize why if you break out each piece of the handlebar expression. See below results:
When you replace \ncustporef with a comma, you are then splitting everything based on commas, but then choosing the first index of the split. In the 3rd output, you see you no longer have access to the 123456 number since you chose index 0 after splitting on the comma. If you change it to use index 1, you'll get what you need.
Tyler Lamparter,
Excellent, thank you for the visualization and explanation!
Please sign in to leave a comment.