Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda