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

305
Visualizações
Can't access variables of JSON response from REST-API in Javascript

I have a problem getting access to the variables in a JSON-File. I get the file as a response from a REST-API. Here you can see the JSON-File:

{
"_embedded": {
    "events": [
        {
            "name": "Josh.",
            "type": "event",
            "id": "Z698xZC2Z17CebP",
            "test": false,
            "url": "https://www.ticketmaster.de/event/josh-tickets/382625?language=en-us",
            "locale": "en-us"

I want to access the value (Josh) of the "name" variable in Javascript in line number 5 and store it into a new variable to use it later.

This ist how I try to do it:

var = data._embedded.events[0].name

But I can't get access to the value attached to "name".

I have read the answers to similar questions here, but there was no solution for me.

I have only read, that it does not work because of the wrong JSON-structure. In other threads, they say there has to be a "{" instead of a "[" in line 3. But I don't know how to change it in javascript directly. I tried it with the JSON.stringify()-method but it didn't work out.

Can somebody help me, please? Is there any way to get access?

I hope you can understand my problem.

Thank you very much!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It seems that your json structure has some errors. The json structure similar to the following is legal. Of course, it is no problem to use a legal structure to exec data._embedded.events[0].name.

const data = {
  "_embedded": {
      "events": [
          {
              "name": "Josh.",
              "type": "event",
              "id": "Z698xZC2Z17CebP",
              "test": false,
              "url": "https://www.ticketmaster.de/event/josh-tickets/382625?language=en-us",
              "locale": "en-us"
          },
          {
              "name": "Josh.",
              "type": "event",
              "id": "Z698xZC2Z17CebP",
              "test": false,
              "url": "https://www.ticketmaster.de/event/josh-tickets/382625?language=en-us",
              "locale": "en-us"
          },
          //...
      ]
   }
}

console.log(data._embedded.events[0].name)

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