Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda