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

Creating a dynamic pulse effect using jQuery to manipulate CSS box-shadow

My goal is to create a pulsating effect using CSS box-shadow through jQuery. Despite my best efforts, the code I attempted failed to produce the desired smooth pulse effect with box-shadow. The code snippet I experimented with: <div class="one"> &l ...

Moving towards the target is a Three.js object

I'm struggling with an issue where the x position of my object moves quicker than the z position, or vice versa. How can I make my object slow down for the x position if the z position requires more time to move? This is the code in my animation func ...

How can JSON-loaded scripts be executed using jQuery?

I received a file with the following content: {'html' : '<div id="bla">something</div>', 'script' : ' $().ready(function() { /* some code */});' } I want to use jQuery to load this file and execute the ...

How can you use the MongoDB Aggregation Framework to filter by a range of dates, group results by individual days, and calculate the average value for each day

I'm currently exploring the possibilities of MongoDB's Aggregation Framework and would appreciate some assistance in enhancing this query to achieve the following objectives: Retrieve Records with Dates falling within a specified range Organize ...

Is it true that node.js arrays can be considered as hashmaps?

Surprisingly, this code is functioning properly in node.js: var arr = new Array(); // also works: var arr = []; arr[0] = 123; arr['abc'] = 456; arr; // node.js: [ 123, abc: 456 ], chrome: [123] I've always believed that an array preserves ...

Conceal the year, month, and day within a datetime-local input

I am working with <input type="datetime-local" step="1"/> input fields, and I want users to only be able to edit the hours, minutes, or seconds. This is due to setting the minimum value using let min = new Date().setHours(0,0,0) and the maximum value ...

Retrieve the weekday dates for a specific year, month, and relative week number using Javascript or Typescript

I am in need of a custom function called getDaysOfWeekDates that can take a year, a month (ranging from 0 to 11), and the week number of each month (usually 4-5 weeks per month) as parameters, and return a list of dates containing each day of that particul ...

The redirection to the HTML page happens too soon, causing the ASYNC functions to fail in saving the user's image and data to the server

Hey everyone! I'm facing an issue with async/await functions. Here's the code snippet from my backend where I'm trying to save details of a newly registered user. I'm puzzled as to why the Redirect() function is executing before the f ...

Activate search bar by clicking on it

I am currently attempting a basic jQuery example to expand a search bar on mouse click, but for some reason, my code is not working as expected. I have a simple jQuery function to display the input field when the button with the class "expand" is clicked, ...

Extract data from dynamically loaded tables using PhantomJS and Selenium Webdriver

I've been informed by everyone that I should be able to retrieve the table content using PhantomJS when working with JavaScript. However, despite my attempts, I have not been successful. My expectation was to obtain the table from the website Page 1 ...

Is there a way to verify DNSSEC compatibility using node.js code?

Struggling with incorporating DNSSEC compliance checks into my web analytics tools using NodeJS. The standard library's dns module does not seem to accept DNSSEC record types such as rrsig, ds, nsec, and nsec3. Despite checking the documentation, thes ...

Retrieve the URL of an image located within an <li> tag within a jQuery selector item array

I am currently using a jQuery slider plugin to display images, and I am attempting to retrieve the URL of the current image when a button is clicked. The slider functions by showcasing all the image slides as list items in a continuous horizontal row. It ...

How can I display a Skeleton when pressing pagination buttons and then turn it off after 3 seconds?

Here is a snippet of my code featuring the use of a Skeleton as a placeholder for CardMedia: {loading ? ( <Skeleton variant="rectangular" width={308} height={420} animation="wave" /> ) : ( <CardMedia s ...

Customizing Magnific Popup: Changing showCloseBtn and closeOnBgClick settings during display

Is there a way to customize the behavior of an open instance of a magnific popup? I want to have different settings for when the popup is closable and when it should be prevented from closing. It appears that these options are only available during initial ...

A guide on transforming a JSON object representing an HTML element into a live HTML element for display on a webpage using C#, JavaScript, or jQuery

I am looking to retrieve a JSON object from a database and convert it into HTML format. Here is an example of the JSON structure: {"input":{ "name":"fname", "type":"text", "placeholder":"Ente ...

What is more effective: utilizing document fragments or string concatenation for adding HTML to the DOM?

My task involves adding a collection of cards to the DOM. html <div class="card"> <div class="card-title">Card 1</div> <div class="card-subtext">This is card 1</div> </div> js let ...

What could be causing my app to struggle with reading a JSON file from my API?

I'm currently working on integrating Retrofit 2 with a Python-made Web Service to request data. Despite receiving a code 200 and being able to see the JSON response for debugging, I keep encountering a "java.lang.IllegalStateException" when using the ...

Looking to organize data based on duplicate values within an array using Javascript in the Vue framework

Can anyone provide assistance? Data = [{"name":A,"val":20}, {"name":B,"val":7}, {"name":C,"val":20}, {"name":D,"val":8}, {"name":E,"val":5}] SortedValue ...

Requesting data from the application to the MongoDB database is currently malfunction

Currently, I'm utilizing Express and passport to develop an application. Everything has been going smoothly so far, but I've encountered a problem when attempting to retrieve data from my mongo database. Strangely enough, I am able to successfull ...

What is the best way to retrieve form values on the server in nextJs?

I'm facing an issue with passing form data to my API endpoint in nextJS. I have set up the form using Formik and Yup for validation. Oddly, when I check the console on the client side, I can see the user input values just fine, but on the server side, ...