Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

377
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!