The $http service encounters an error while attempting to retrieve a JSON file from the server

When attempting to fetch a file from the server, I utilize the $http service in the following manner:

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

For some mysterious reason, an exception is only thrown when trying to retrieve JSON files from the 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; it is attached in the question.

If it's a plain text file or even the same file with a comment added above the JSON data, no exception occurs.

If anyone has any insights into why this error is happening, your input would be greatly appreciated :)

Thanks

Non-functional file:

{
  "users": [
    {
      "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5f1eac0c6d0c784f5d087d09bd6dad8">[email protected]</a>",
      "nickName": "D_user1e2e"
    }
  ],
  "groups": [
    {
      "name": "D_BETWEEN_INSTANCES",
      "description": "GROUP OF USERS FROM ALL INSTANCES",
      "members": [
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c696f796e2a5c792e79327f7371">[email protected]</a>",
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6928361c1a0c1b5f290c5b0c470a0604">[email protected]</a>",
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99dbc6eceafcebafd9fcabfcb7faf6f4">[email protected]</a>",
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6622391315031457260354034805090b">[email protected]</a>"
      ]
    },

  ]
}

Functional file:

tests
 {
  "users": [
    {
      "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="51150e2422342360113463347f323e3c">[email protected]</a>",
      "nickName": "D_user1e2e"
    }
  ],
  "groups": [
    {
      "name": "D_BETWEEN_INSTANCES",
      "description": "GROUP OF USERS FROM ALL INSTANCES",
      "members": [
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8afff9eff8bccaefb8efa4e9e5e7">[email protected]</a>",
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5a4ba90968097d3a580d780cb868a88">[email protected]</a>",
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d0f12383e283f7b0d287f28632e2220">[email protected]</a>",
        "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="581c072d2b3d2a69183d6a3d763b3735">[email protected]</a>"
      ]
    },

  ]
}

Answer №1

Take out the , symbol from this section-

"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="783c270d0b1d0a49381d4a1d561b1715">[email protected]</a>"
      ]
    },

similar to this-

"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3672694345534407765304531855595b">[email protected]</a>"
      ]
    }

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

How to convert JSON data to CSV using a for loop in Python

Does anyone know how to correct my formatting issue? I have figured out how to retrieve the header and export the data in json format to a file. The challenge I'm facing is assigning the item index to each line in every column. data = json.loads(res ...

Developing a foundational class for personalized JSON entities

I'm currently in the process of designing a base class for initializing customized JSON objects. One of the main reasons I am pursuing this approach is to eliminate the need to repeatedly duplicate the same function (updateResultsDictionary) across va ...

Obtain the text content of a div using JavaScript

Hello, I am new to Javascript! I have a table structure that looks like this: <table id='master_tbl'> <tbody> <tr id="master_hr'> <td class="myclass"> <table> <tbody ...

Unable to pass an event parameter using my this.handleChange function in react-native

Encountering an issue with the error message "undefined is not an object (evaluating 'event.preventDefault)" It appears that I am unable to pass an event parameter to the handleChange function in my child component, which is being rendered in the par ...

I encountered a problem with routing in my MERN project while trying to implement a feature I learned from a YouTube tutorial

My first question on stackoverflow. To summarize: I followed a YouTube video and downloaded the course code from the GitHub link provided, but I'm encountering routing issues despite reading similar questions on stackoverflow. I've been followi ...

Enhancing AngularJs with jQuery animations: Mastering the art of fade in and fade out effects

I am new to AngularJS and I have a task that requires me to: I currently have a div and a button. My goal is to create an ajax call when the button is clicked, and upon completion, I would like to either delete the existing div or add a new one. I want ...

Interactive tooltip with hyperlinks powered by jQuery

Is it possible to create a pop-up window with links that behave like a normal tooltip but can be clicked on by the mouse? How can this functionality be achieved without losing focus when hovering over the links causing the window to close? jQuery(docume ...

Transform XML data into JSON format without considering any attributes

I'm currently working on a project in JAVA where I need to convert XML to JSON while excluding tag attributes from the XML. Although I attempted using org.json.XML, it didn't fully align with my requirements. Does anyone know of a library that ...

Obtain JavaScript object from WebView in Swift

Currently, I am displaying a webView in my iOS app using Swift. My goal is to retrieve an object from the JavaScript code within the webView. Upon inspecting the console, I discovered that the desired object is named "window.user". However, when attempti ...

Unexpected issue with Typo3 v9 - receiving empty Ajax Plugin JSON response

Consider the following setup in TYPO3 for an ajax request: ajaxAutocomplte_page = PAGE ajaxAutocomplte_page { typeNum = 111871 10 = COA_INT 10 { userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run extensionNa ...

What is the best way to verify async actions that update the UI in my React Native application?

Currently, my setup involves utilizing jest alongside @testing-library/react-native. Below is a snippet of code: Upon clicking a button, a function is dispatched: onPress(_, dispatch) { dispatch(getUserAddresses()); }, This dispatched functi ...

When using the map function, I am receiving an empty item instead of the intended item based on a condition

Need assistance with my Reducer in ngRx. I am trying to create a single item from an item matching an if condition, but only getting an empty item. Can someone please help me out? This is the code for the Reducer: on(rawSignalsActions.changeRangeSchema, ...

The JavaScript filter function will only return arrays that have matching IDs

How can I filter out book data based on the author's id? I have a list of books with various author ids, and I want to only return the books that match a specific author id. However, my current filtering method doesn't seem to work correctly as i ...

Displaying live content within ngRepeat

Having trouble displaying dynamic content within an ngRepeat. Whenever I try to display my promise content, I'm seeing an empty object {}: <div ng-controller="DemoCtrl"> <div class="sidebar" ng-repeat="row in rows"> <div cl ...

Learn the process of converting JSON to object in Python or Django

As a newcomer to python and django, I am required to interact with a web service that returns JSON responses structured like this: [{'name': 'gfile1.txt', 'length': 448, 'createdDate': '1582229671352'}, {& ...

Specify the controller to be used dynamically in an Angular directive

I want to be able to specify the controller that a directive uses by adding an attribute to the element - in other words, dynamically: HTML <div data-mydirective data-ctrl="DynamicController"></div> Angular angular.module('app', [ ...

Is the sudden disconnection from Chrome after a WebSocket handshake related to a domain mismatch or is it possibly a bug in Chrome?

I created my own WebSocket server using Python, but I encountered an issue where Chrome 4.0.249.78 dev (36714) always disconnects after the handshake process. Wanting to rule out any issues with my code, I tested it using the WebSocket server from , only t ...

What is the process for declaring an exported type variable in React?

I have created a unique configuration in a different file: //config.js export const config = [ { id:0, name:"Config 1", }, { id:1, name:"Config 2", }, { id:2, name ...

Discover the ins and outs of utilizing nested form associations within Phoenix

Currently diving into Phoenix 1.3 and eager to grasp ecto associations while leveraging Angularjs for the frontend. Two schemas at play: user.ex and profile.ex Both created using mix phx.gen.json user.ex schema "users" do field(:password_hash, :string) ...

Interactive data visualization with hover-over details

I am utilizing datamaps to showcase the countries of the world, however, I want the graph to be centered. The issue arises when I hover over a country and the pop up appears all the way to the left, aligned with where the country would be if it wasn't ...