Skip to main content
Best answer

Formatting json data from webhook into text

  • March 10, 2023
  • 17 replies
  • 4729 views

Forum|alt.badge.img

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.  

Best answer by Troy Tessalone

@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

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

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

Hi @hannah L 

Good question.

Try using a Code step to parse the JSON.

 


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

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.


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

@hannah L 

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


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

ok! here are the screenshots 

 


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

Hi @hannah L 

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


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

Now getting this : 

TypeError: Cannot read property 'trim' of undefined


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

@hannah L 

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

Please post screenshots of your encountered error message.


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

 


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

@hannah L 

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

Please post the other encountered error message after testing.


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

I really appreciate the help!


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

@hannah L 

Please clarify what Formatter action is being used in Step 2


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

 


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

@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.

 


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

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”?


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 10, 2023

@hannah L 

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


Forum|alt.badge.img
  • Author
  • Beginner
  • March 10, 2023

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

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • Answer
  • March 10, 2023

@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