Liad Livnat Liad Livnat - 6 months ago 19
AngularJS Question

$http service throw exception when downloading json file from server

When trying to download a file from server i use $http service as following:

$http({url: url, method: "GET", withCredentials: true});


for some unkown reason only json files causing an exception when getting from server:

SyntaxError: Unexpected token ] in JSON at position 1362
at Object.parse (native)
at tc (https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:14:245)
at bc (https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:77:7)
at https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:77:369
at q (https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:7:322)
at dd (https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:77:351)
at c (https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:78:495)
at https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:112:182
at m.$eval (https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:126:250)
at m.$digest (https://sharon-staging.comilion.com/app/bower_components/angular/angular.min.js:123:365)


The json file is valid, i attached him in the question.

if it's a text file, or even the same file that i added a comment above the json, there is no exception.

If anyone have an idea why do i get this error, it will really really help :)

Thanks

not working file:

{
"users": [
{
"email": "D_user1@e2e.com",
"nickName": "D_user1e2e"
}
],
"groups": [
{
"name": "D_BETWEEN_INSTANCES",
"description": "GROUP OF USERS FROM ALL INSTANCES",
"members": [
"user6@e2e.com",
"A_user6@e2e.com",
"B_user6@e2e.com",
"D_user1@e2e.com"
]
},

]
}


working file:

tests
{
"users": [
{
"email": "D_user1@e2e.com",
"nickName": "D_user1e2e"
}
],
"groups": [
{
"name": "D_BETWEEN_INSTANCES",
"description": "GROUP OF USERS FROM ALL INSTANCES",
"members": [
"user6@e2e.com",
"A_user6@e2e.com",
"B_user6@e2e.com",
"D_user1@e2e.com"
]
},

]
}

Answer

Remove the , sign from here-

"D_user1@e2e.com"
      ]
    },

like this-

"D_user1@e2e.com"
      ]
    }