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

103
Visualizações
JSON value returned as undefined when we fetch JON.parse data present in the depth of JSON using javascript

Related to this post : Parsing JSON to object using JSON.parse

I am facing similar issue and using console.dir(responseData.data, { depth: null }) i am able to get full text for 'credApp' field. However, When i try to access the element like 'responseData.data.orderItems.credDecision.credApp' to validate it against another variable then I get 'credApp' value as undefined.

I am able to get the values till credDecision such as responseData.data.orderId. Is there anyway to resolve this issue. Any help is much appreciated.

here is the code:

const getResponseData = (url) => new Promise((resolve, reject) => {
http.get(url, res => {
const { statusCode } = res;
const contentType = res.headers['content-type'];
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => { rawData += chunk; });
res.on('end', () => resolve({ statusCode, contentType, rawData }));
}).on('error', e => reject(e));
});

const responsePayload = await getResponseData(api_url+ orderNumber);

var responseData = JSON.parse(responsePayload.rawData);
console.dir(responseData.data, { depth: null });
var orderId = responseData.data.orders.externalOrderId;
var credApp = responseData.data.orderItems.credDecision.credApp;

Posting a sample part of api response since the response payload is large, I am trying to fetch OriginalOrderId and it is returned as undefined when I convert it into JSON and validated against another field:

"data": {
  ringId: '1',
  consumerId: '2',
  orderSummary: {
    guestCheckout: null,
    id: '1233'
    orders: [{
      orderId: 'ABC1233',
      orderType: '1'
    }],
    dateCreated: '2021-10-18T16:28:46.964Z',
    createdBy: 'User1'
  },
  orders: [{
    OriginalOrderId: '9693'
  }]
}
about 4 years ago · Juan Pablo Isaza
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