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

382
Vistas
Reading a JSON file: Fix with square brackets [ ] with javascript

any way to read a JSON file with rectangle brackets with javascript

example:

[{"c_title":"Sachertorte","c_startdate":1586941500000,"c_enddate":1586945100000,"c_location":"Dortmund","c_isallday":0,"c_description":"Logineo-Konferenz","calendarRange":null},{"c_title":"Ende der Osterferien","c_startdate":1587333600000,"c_enddate":1587419999000,"c_location":"","c_isallday":0,"c_description":"","calendarRange":null}]

I have this code in javascript to read the json but without the rectangular brackets

<body>
    <div class="mypanel"></div>

    <script>
    $.getJSON('', function(data) {

        var text = `Date: ${data.c_title}<br>
                    Time: ${data.c_startdate}<br>
                    Unix time: ${data.c_enddate}`


        $(".mypanel").html(text);
    });
    </script>

</body>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Technically the square brackets indicate that this is an array with one object item in it.

Therefore in order to really use it this way you'd need to read the data this way:

var text = `Date: ${data[0].c_title}<br>
            Time: ${data[0].c_startdate}<br>
            Unix time: ${data[0].c_enddate}`

The [0] means you're grabbing the item at index 0 in the array (i.e. the first - and only - item).

This will obviously ignore any additionally items in the array, but if you're only ever expecting one object in the array then this will work fine.

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