Encountered a SyntaxError: Unexpected token "e" while attempting to parse a JSON string

When I attempt to use JSON.parse in order to convert the string below into a JavaScript object, I encounter an "Uncaught SyntaxError: Unexpected token e" error.

{
    "__type": "HRIS.oHRData, HRIES, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
    "TPDDListValue": new Ajax.Web.DataSet([]),
    "DPDDListValue": new Ajax.Web.DataSet([]),
    "TopDataValue": new Ajax.Web.DataSet([
        new Ajax.Web.DataTable([
            ["HID","System.String"],
            ["HFrName0","System.String"],
            ["HFtName0","System.String"],
            ["HGFName0","System.String"],
            ["HFmName0","System.String"],
            ["TID","System.Byte"]
        ],[
            ["123456789","ABCD1","ABCD2","ABCD3 ","ABCD4",2]
        ])
    ]),
    "DownDataValue": new Ajax.Web.DataSet([]),
    "MenuDataValue": new Ajax.Web.DataSet([]),
    "SearchReturnValue": new Ajax.Web.DataSet([]),
    "Result": null,
    "NewID": "NoID",
    "AffectedRecords": 0
}

This is the code snippet that I am using:

var text= 'the json string here';

var obj=JSON.parse(text);

I suspect that the problem lies in JSON's inability to recognize the type of new Ajax.Web.DataSet([])

If you have any suggestions on how to resolve this issue, please share them with me.

Your input is highly appreciated.

Thank you very much,

Answer №1

When inserting this code snippet, remember that you do not need quotation marks and there is no need to parse it:

let myObject = {
    "__type": "HRIS.oHRData, HRIES, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
    "TPDDListValue": new Ajax.Web.DataSet([]),
    "DPDDListValue": new Ajax.Web.DataSet([]),
    "TopDataValue": new Ajax.Web.DataSet([
        new Ajax.Web.DataTable([
            ["HID","System.String"],
            ["HFrName0","System.String"],
            ["HFtName0","System.String"],
            ["HGFName0","System.String"],
            ["HFmName0","System.String"],
            ["TID","System.Byte"]
        ],[
            ["123456789","ABCD1","ABCD2","ABCD3 ","ABCD4",2]
        ])
    ]),
    "DownDataValue": new Ajax.Web.DataSet([]),
    "MenuDataValue": new Ajax.Web.DataSet([]),
    "SearchReturnValue": new Ajax.Web.DataSet([]),
    "Result": null,
    "NewID": "NoID",
    "AffectedRecords": 0
};

It is important to note that the Ajax object must be available for this code to function properly.

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

Tips for including a state in an API fetch request

Why does my API fetch work when the state is an empty string, but not when there is a string inside the state? Check out the examples below to see the issue. The concept is that the user inputs new text in an input field which updates the Search state and ...

Running a Chrome content script once an AJAX request has been triggered by the <body> element

I am facing a challenge with running the content script before the DOM is fully loaded. To give context, there is an AJAX request within a tag which gets triggered on $(document).ready(). Once this request is completed, my extension code kicks in. To tra ...

Merging two arrays concurrently in Angular 7

When attempting to merge two arrays side by side, I followed the procedure below but encountered the following error: Cannot set Property "account" of undefined. This is the code in question: acs = [ { "account": "Cash In Hand", ...

Sending a request via AJAX to retrieve a complicated object

Programming Environment: ASP.NET, jQuery Below is the AJAX call I am using: var tempVar = JSON.stringify({plotID:currentId}); $.ajax({ type: "POST", url: "testPage.aspx/getPlotConfig", data: tempVar, contentType: ...

Eliminate operation in React with the help of Axios

Within my React application, I have implemented a callback method for deleting data from an API using the axios library: deleteBook(selectedBook) { this.setState({selectedBook:selectedBook}) axios.delete(this.apiBooks + '/' + this.select ...

What are some possible reasons or solutions for Axios sending a 404 error?

Hi there, I'm completely new to the MERN stack and I'm encountering an issue when trying to post data using Axios and Express. I may have misunderstood something, so here's my problem. I have a form on a page that I am attempting to use to s ...

Access the system by logging in with a stored Google account

I have experience integrating "Login via Google account" on various websites. However, some sites like Zomato always display the option to login via Google as soon as you open them. They even show a list of Google accounts that I have previously logged i ...

Developing a password strength checker using Javascript for ultimate security

Currently encountering an issue with my javascript project. The main goal is to validate user input against a list of known bad passwords and also their "1337" versions. Initially, checking for the basic bad password list was straightforward. However, th ...

Mastering the Art of Merging 3 Arrays

Greetings to the Community I have a question regarding my code. I am looking to merge three variables together. $result = mysqli_query($con, "SELECT disease,age,SUM(CASE WHEN gender = 'm' THEN 1 ELSE 0 END) AS `totalM`, SUM(CASE WHEN gender ...

angular-recaptcha: Adjusting language based on the website's language update

My website offers three different languages that users can switch between. The language switch functionality is implemented on the client side using JavaScript (AngularJS). I have integrated reCAPTCHA 2 into my website and now I need to update the languag ...

Chart rendering failure: unable to obtain context from the provided item

I am encountering an issue while trying to incorporate a chart from the charts.js library into my Vue.js and Vuetify application. The error message that keeps popping up is: Failed to create chart: can't acquire context from the given item Even af ...

The v-for loop seems to be malfunctioning in my Nuxt 3 project

I have a script with mock data stored in a variable named whatsHappeningItems, and I am trying to pass this data as a reference to a card component using v-for="whatsHappening in whatsHappeningItems". However, when I do this, I encounter the following erro ...

The search feature in my React Pagination is not performing as effectively as expected

I recently set up a React app that interacts with a MongoDB database using an Express Server. The pagination feature is working smoothly, but I encountered an issue with the search function. It only works when typing in the input box; deleting characters d ...

Ways to package object fields within an array

I am in possession of an object with various properties, ranging from arrays to objects. My goal is to transform the object so that each sub field is encapsulated within an array. For instance: "head": { "text": "Main title", "su ...

What is the process for modifying JSON attributes with JavaScript?

One JSON data set is provided below: [{ ID: '0001591', name: 'EDUARDO DE BARROS THOMÉ', class: 'EM1A', 'phone Pai': '(11) 999822922', 'email Pai': '<a href="/cdn-cgi/l/em ...

Dynamically assigning a name to a variable through code

Is there a quicker way to complete these 100 tasks? variable_1 = 1; variable_2 = 2; variable_3 = 3; ... variable_100 = 100; I attempted to use the following code: for(var i = 1; i <= 100; i++) { variable_ + i = i; } However, I encountered an e ...

Tips for removing the default hover and click effects from a Material-UI CardActionArea

Check out the card sample with a lizard photo on https://material-ui.com/components/cards. When you hover over the cardActionArea, it will get darker or lighter based on the theme. Clicking on the card will make the picture change its brightness relative ...

Error in scrolling previews detected in Jssor horizontal template maker

I've been working with Jssor Slider Maker and I'm using the vertical preview template that features two columns on the left side and a maximized image on the right side. After pulling the code from the developers pack, it includes scripts, CSS an ...

Permit the use of the "&" character in mailto href links

When including an email mailto href link and using a & character in the subject, it can cause issues with code rendering. For example, if the subject is "Oil & Gas," only "Oil" may show up. In most cases, you could simply replace the & with th ...

Using jQuery and Perl to create a dynamic progress bar that is based on the current state of a "pipeline file" and utilizes AJAX

I'm looking to create a small pipeline that enables users to select a file and run multiple scripts using it as an input. Some of these scripts may take several minutes to complete (time depends on the file's size), so I want to display a progres ...