Error: JSON parse error, unexpected '[' character at index 1367

My AngularJS front-end is connected to the backend using Restangular and a Java Servlet, which returns JSON data that is parsed to create a chart with Charts.js

Angular Factory

app.factory('graphService', function($http, Restangular) {

            var exports = {};

            exports.getRestangular = function() {
                return Restangular.setBaseUrl("/apm/graph");
            };

            exports.getGraphDataDC = function(dcName) {
                return exports.getRestangular().all("graphData/DC/" + dcName).getList();
            };
}

Angular UI RestangularCall

graphService.getGraphDataDC(item.name).then(function (data) {
                        $scope.summary = data;
                        $scope.JSONtoArrays(data);
                        console.log(data);
                        $scope.createChart();
                    }, function(data) {
                        //Error
                    });

Java Servlet

try
{
        dcData = persistance.getSummaryDelaysDC80Perc(from, to, pathInfo[pathInfo.length-1]);
        } catch(RuntimeException e) {
        LOGGER.error("Could not load data form database, reason: {}", e);
            throw new ServletException(e);
        }
    
    json = ThreadsafeUtils.getGsonInstance(pretty).toJson(dcData);
    LOGGER.debug(dcData.size() + " summary entries were read");

        out.write(json);
        break;
}

Persistence Facade This function is called by the Servlet

public List<SummaryDelaysDataCenter80Perc> getSummaryDelaysDC80Perc(Date from, Date to, String dcName)  throws RuntimeException {
        List<SummaryDelaysDataCenter80Perc> result = new ArrayList<>();

        Calendar c = Calendar.getInstance(Locale.GERMANY);
        java.sql.Date minDate;
        java.sql.Date maxDate;
        String call;
        if (from != null)
            minDate = new java.sql.Date(from.getTime());
        else
            minDate = Utils.getDBMinDate();

        if (to != null) {
            maxDate = new java.sql.Date(to.getTime());
        } else {
            maxDate = Utils.getDBMaxDate();
        }
        call = "CALL " + summaryDelaysDCProcedureName + "(?, ?, ?, ?)";

        try {
           
            java.sql.Connection connection = em.unwrap(java.sql.Connection.class);
            java.sql.CallableStatement cst = connection.prepareCall(call);

            cst.setDate(1, minDate, c);
            cst.setDate(2, maxDate, c);
            cst.setString(3, dcName);
            
            cst.execute();
            ResultSet rs = cst.getResultSet();
            while (rs.next()) {
                SummaryDelaysDataCenter80Perc sdeldc80 = new SummaryDelaysDataCenter80Perc();
                DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY);
                String strDate = dateFormat.format(rs.getTimestamp(1));
                sdeldc80.setName(rs.getString(2));
                sdeldc80.setDate(strDate);
                sdeldc80.setPerc80serverdelay(Double.toString(rs.getDouble(3)));
                sdeldc80.setPerc80networkdelay(Double.toString(rs.getDouble(4)));
                sdeldc80.setPerc80clientdelay(Double.toString(rs.getDouble(5)));
                sdeldc80.setPerc80roundtrips(Long.toString(rs.getLong(6)));
                result.add(sdeldc80);
            }
        } catch (java.sql.SQLException e) {
            throw new RuntimeException("StoredProcedureCall was not successful", e);
        }
        return result;

    }

The converted JSON data looks like:

[{"Name" : "WER", "Count" : 90, "Date": "2016-05-25" }, 
{"Name" : "TWK", "Count" : 17, "Date": "2016-05-26"  }, 
{"Name" : "XPR", "Count" : 26, "Date": "2016-05-27"  }]

Although the Java Servlet code runs without errors, there is an issue when assigning values to $scope.summary, resulting in an error related to JSON parsing.

The JSON string's length is 1367 characters, but the error message points to position 1367, causing confusion.

How can I investigate and resolve this JSON parsing error?

Answer №1

Consider utilizing JSON.parse(data) before proceeding with additional tasks.

Answer №2

Problem solved! Turns out there was a missing break statement in the persistence facade.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with method execution within Java NetBeans constructor after building the project

When running my Java project in Netbeans, everything works fine. However, after building the project, the items are not added to the combobox as they should be. Below is a sample code snippet: Login JFrame public class Login_Frame extends javax.swing.JF ...

Tips for making a dynamic active button using javascript

I'm trying to create a toggle button with eight buttons. When seven out of the toggle buttons are clicked, it should toggle between two classes and change its CSS styles. If the daily button is clicked, it should toggle the styles of the other seven b ...

Adjusting the front size while utilizing the SideNav feature in Materialize

While creating a website using Symfony and Materialize, my client requested to have the menu displayed on the side. I followed the guidelines from and successfully implemented the side menu on the left. However, I am encountering two issues: The first ...

Conceal blank fields in print layout using JavaScript

I need help with a form that needs to be printed, but I want to exclude any blank fields from the print view when using the JavaScript window.print(); function and its print window. Is there a possibility to implement logic to handle this situation before ...

Using percentages for sizing and margins in CSS

Looking to create a visually appealing page that always fills the entire screen? Check out this code snippet that does just that: #posts{ width:100%; height:auto; background:#666; } .entry{ float:left; margin-left: 4%; margin-top:10 ...

What's the best way to extract and display a specific portion of a JSON file using Python?

Hello, I am a beginner in Python and I am trying to figure out how to extract specific data that is enclosed within curly brackets in a JSON file. Even though the JSON file has many curly brackets, I am interested in extracting the data from just one pai ...

Is there a way to remove the "next" button from the last page in a table?

I'm currently working on implementing pagination for my table. So far, I have successfully added both the "next" and "previous" buttons, with the "previous" button only appearing after the first page - which is correct. However, I am facing an issue w ...

"Utilize the JavaDoc formatting feature in Intellij IDEA to

Is there a way to format the return statement so that it aligns to the same level as the parameter description? Visit the image below for reference: https://i.sstatic.net/a020d.jpg I am aiming to align the second line of the return statement with the firs ...

React's useState Hook: Modifying Values

I just started learning about React and React hooks, and I'm trying to figure out how to reset the value in useState back to default when new filters are selected. const [apartments, setApartments] = React.useState([]) const [page, setPage] = React.us ...

Prevent users from navigating back in their browser with jQuery

As I work on developing an online testing app, one of the requirements is to prevent users from refreshing the page or going back during the test until it has ended. While I have successfully disabled the refresh action in jQuery using various methods with ...

Can all browser console messages and errors be sent to a different machine using a pipeline?

Currently, I am in the process of troubleshooting a javascript error that is occurring within a Cordova app's InAppBrowser on an Android device. Despite being able to connect to the web-view on the phone using Chrome's remote debugging tools, the ...

Executing mathematical calculations within a JavaScript object

Can an equation be executed inside an object? For instance: var taxes = { gst: '0.10', }; var prices = { first_key: '437.95', total_key: parseFloat(prices.first_key * taxes.gst).toFixed(2), ....... }, }; Or do I n ...

Update the MySQL database conditionally depending on whether a column value has reached a specific final state, such as -1

Imagine having a table with three columns - ID, Name, and Status. The Status column can have values of -1, 0, 1, or 2. Initially, the default value is always 0, but upon update, it can change to 1, 2, or -1. Is there a way to enforce a constraint where onc ...

Lazy serialization in Protobuf streaming API

Our Android app utilizes Protocol Buffers for storing application data. The data is structured in a way where a single protobuf ("container") holds a list of other protobufs ("items") as a repeated field: message Container { repeated Item item = 1; } ...

ListActivity not displaying Actionbar

I am facing an issue where I cannot see my actionbar when the MainActivity extends ListActivity. After researching, it seems like the problem lies with the theme. I tried changing <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> t ...

When going through a list of children, it is important that each one has a distinct "key" property. This is essential for properly iterating over divs

I am encountering the following warning message: "Each child in a list should have a unique "key" prop. Check the render method of Todo. in TodoItem (at ToDo.js:14)" Here is the code snippet: import React from 'react'; import ...

Exploring the capabilities of referencing MongoDB documents with the populate method in Node.js

I have been working on referencing in Node.js using the populate method, but I am unsure about how exactly it works. In my code, I am creating a reference to the user collection from my child collection. I have two collections - one for children and anothe ...

I'm having trouble getting my bot command handler to function properly

When it comes to my command handler, the commands function properly. However, when I attempt to include arguments like $user-info @user instead of just $user-info, it returns an error stating that the command is invalid. Code //handler const prefix = &ap ...

Determining the ultimate height of an element as it transitions in size using CSS

In situations where a CSS transition is ongoing, jQuery will return the current height of an element when its dimensions are requested. However, this may not always be desired. There are many cases where it's necessary to retrieve the final dimensions ...

Self-restricting generic types

Are there any noticeable distinctions between this standard piece of code: public class SelfBounded <T extends SelfBounded<T>>{} and this alternative version? public class SelfBounded <T extends SelfBounded>{} If so, how can one disti ...