Best answer

Formatting json data from webhook into text


Userlevel 1
Badge

What is the best way to get this json response into a format for my next zap?

Right now i am getting back a jsob blob that looks something like 

 

I want to take this info coming from my webhook response and map the fields into an Action for a CRM, but i can’t figure out a way to easily transform that info format wise.  

icon

Best answer by Troy Tessalone 10 March 2023, 20:58

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

17 replies

Userlevel 7
Badge +14

@hannah L

It’s possible with Code, but it means the JSON would have to be handled/prepped in the Code step before trying to pass it to the JSON.parse() method.

If you need help, consider hiring a Certified Zapier Expert: https://zapier.com/experts/automation-ace

Userlevel 1
Badge

Essentially the entire “raw body” , we want to use to send to a crm for example: {"ContactId":1701,"LoanId:2551","LoanUrl":"https://my.dev.xx.tech/loan?xxx",LoanId":"xx","RefId":"xx","FirstName":"John","LastName":"Homeowner","Email":"john.xx.3.10.2023.1007a@test.xx.com",”

I would want to come out like:

  • Contactid: 1701
  • LoanId: 2251
  • LoanUrl: 
  • Firstname: xx
  • LastName: xx
  • Email: xx
Userlevel 7
Badge +14

@hannah L 

What data from the JSON do you need parsed out to use in other Zap steps?

Userlevel 1
Badge

Okay, if i cant change that do you have any other suggestions to recommendations for how to get to the end result being “formatting this data so that i can send it to another app”?

Userlevel 7
Badge +14

@hannah L 

This help article explains the error: https://itsjavascript.com/unexpected-token-u-in-json-at-position-0

It means the JSON would have to be handled/prepped in the Code step before trying to pass it to the JSON.parse() method.

It may be related to this parameter for which the value doesn’t have the double quotes.

 

Userlevel 1
Badge

 

Userlevel 7
Badge +14

@hannah L 

Please clarify what Formatter action is being used in Step 2

Userlevel 1
Badge

I really appreciate the help!

Userlevel 7
Badge +14

@hannah L 

Ok, go head and remove the .trim().

Please post the other encountered error message after testing.

Userlevel 1
Badge

 

Userlevel 7
Badge +14

@hannah L 

That error makes it should like the mapped variable had “No data”.

Please post screenshots of your encountered error message.

Userlevel 1
Badge

Now getting this : 

TypeError: Cannot read property 'trim' of undefined

Userlevel 7
Badge +14

Hi @hannah L 

Try adding .trim() after the inputData.RAW to get inputData.RAW.trim()

Userlevel 1
Badge

ok! here are the screenshots 

 

Userlevel 7
Badge +14

@hannah L 

We’d need to see detailed screenshots with how your Zap steps are configured, thanks.

Userlevel 1
Badge

thanks @Troy Tessalone ! I tried that but i am getting .

SyntaxError: Unexpected token u in JSON at position 0” as an error 

I should also note that in the input data, i am using the “Raw Body” from my webhook zap.

Userlevel 7
Badge +14

Hi @hannah L 

Good question.

Try using a Code step to parse the JSON.