Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Getting JSON element is not working when I try JSON.parse

When console logging the event object using JSON.stringify(event) I get the below output.

 {
    ...
    "body": "{\"vox\":{\"id\":10431,\"summary_text\":\"Vox received from 978-1913905101 via Book reviews at 17:17 (UTC) on 26/01/2022\",\"send_time\":\"2022-01-26T17:17:51.812Z\",\"contact_email\":\"\",\"contact_phone\":\"\",\"channel_name\":\"Book reviews\",\"channel_public_name\":\"telbee\",\"duration\":1,\"vox_context\":null,\"channel_id\":2786,\"recording_url\":\"https://api.telbee.io/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBczh6IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--9fdab42822e2a9235f03ca178ae917a83941b6cd/Wed%20Jan%2026%202022%2019-17-51%20GMT+0200%20(Eastern%20European%20Standard%20Time)\",\"direction\":\"vox_in\",\"channel_status\":\"active\",\"transcription_state\":\"not_transcribed\",\"share_link\":\"https://app.telbee.io/vox/Djw3em5mEMse6yjM5aA4S6oM\",\"vox_no\":2,\"sending_user\":null,\"contact_name\":\"978-1913905101\",\"contact_id\":6275,\"actual_transcription\":\"\",\"transcription_language\":\"en-US\",\"conversation_inbox_url\":\"https://app.telbee.io/inbox?token=iP9jHf2KVVrZuZRoe7n9NFLT\",\"sending_user_id\":null}}",
    "isBase64Encoded": false
}

But when I try to get the vox element of the body it fails

console.log('event body = ' + JSON.parse(event.body.vox.contact_name));

The error message is

{
    "errorType": "TypeError",
    "errorMessage": "Cannot read property 'contact_name' of undefined",
    "stack": [
        "TypeError: Cannot read property 'contact_name' of undefined",
        "    at Runtime.exports.handler (/var/task/index.js:49:69)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}

I'm not sure how to get access to event.body.vox.contact_name even though I know it's there in the payload I cant get access to it. I know I have to parse it first as it is escaped but the console.log does not allow me to access the event objects body element. I'm not sure what the issue could be as this is the event payload that is passed into this lambda function that I am creating and is attached to an AWS Gateway.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are trying to get a value before parsing.Try this

var body=JSON.parse(event.body);
var contactName=body.vox.contact_name; // 978-1913905101
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!