JSON.parse: unexpected character at line 1 column 2 of the JSON data
This seems to be a common "problem" but i could not find a solution somewhere else, so im asking here.
I get this with ajax from an flask app, which seems to be valid json (at least to me).
{
"payload": {
"data": [
10,
267,
34,
376
],
"labels": [
"NEW LPARS",
"ACTIVE LPARS",
"DISABLED LPARS",
"ALL LPARS"
]
}
}
The jquery part which is meant to draw a simple Chart.js Bar Chart.
- // top bar chart begin
- $(document).ready(function(){
- var _data;
- var _labels;
- $.ajax({
- url: "/get_chart_data",
- type: "GET",
- data: {key: 'top_bar'},
- success: function(response) {
- full_data = JSON.parse(response.payload);
- _data = full_data['data'];
- _labels = full_data['labels'];
- },
- error: function(result) {
- alert("Error");
- }
- });
- new Chart(document.getElementById("bar-chart-top"), {
- type: 'bar',
- data: {
- labels: _labels,
- datasets: [{
- data: _data,
- label: "LPAR COUNT",
- borderColor: "#3e95cd",
- backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9"],
- fill: true
- },
- ]
- },
- options: {
- legend: { display: false },
- title: {
- display: true,
- text: 'LPAR STATUS'
- }
- }
- });
- });
- // top bar chart end
I always get "SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data".
any hints whats wrong?