Error: JSON parsing encountered an unexpected number

My JSON string:

const jsonData = '{"start_date_time": ["2012-12-05 04:45:42.135000", "None"], "terminal_no": ["T1081", "None"], "master_doc_no": ["100008", "100008"], "notes": ["", ""], "doc_no": ["1000018", "1000019"], "location_code": ["1005", "1005"], "end_date_time": ["2012-12-05 05:27:04.529000", "None"], "doc_status": ["CC Ended", "Draft"], "bc_list": ["[{\"465\":\"85\"},{\"306\":\"6\"},{\"306\":\"47\"},{\"306\":\"366\"},{\"306\":\"634\"}]", "[{\"257\":\"14\"}]"]}';
JSON.parse(jsonData);

However, I'm encountering a SyntaxError: Unexpected Number.

Could someone please point out where the issue might be in my code?

Answer №1

To simplify, focus on the problem area, which is within bc_list...

JSON.parse('{"bc_list": ["", "{\"257\":\"14\"}]"]}')

The issue arises from the backslashes being misinterpreted in JSON.parse(). You need to escape them as well.

JSON.parse('{"bc_list": ["", "{\\"257\\":\\"14\\"}]"}')

Your corrected line should look like this:

JSON.parse('{"start_date_time": ["2012-12-05 04:45:42.135000", "None"], "terminal_no": ["T1081", "None"], "master_doc_no": ["100008", "100008"], "notes": ["", ""], "doc_no": ["1000018", "1000019"], "location_code": ["1005", "1005"], "end_date_time": ["2012-12-05 05:27:04.529000", "None"], "doc_status": ["CC Ended", "Draft"], "bc_list": ["[{\\"465\\":\\"85\\"},{\\"306\\":\\"6\\"},{\\"306\\":\\"47\\"},{\\"306\\":\\"366\\"},{\\"306\\":\\"634\\"}]", "[{\\"257\\":\\"14\\"}]"]}')

Avoid using JSON data embedded within strings inside JSON data. It can lead to complications.

Answer №2

If you encounter this error, it typically indicates that you have either omitted an operator or used an illegal operator in your calculation.

For instance:

var x = 500 / 2; // correct
var y = 500 2;   // incorrect
var z = 5678;     // correct
var w = 2,345;    // incorrect

Variables y and w will trigger the following error:

Uncaught SyntaxError: Unexpected number

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

problem with concealed picture when hovering cursor

While I know this issue has been discussed before, I am facing a slight confusion regarding displaying an image on MouseOver. Currently, I have a div container with a colored background that shows when hovered over. You can see an example of this here - sc ...

Using ReactJS, the for loop can be utilized to dynamically create buttons and assign variables based on the integer being iter

I need some help with ReactJS. I'm trying to generate 10 buttons using a for loop and assign a variable with the iteration number, but when I use the function setMqty(i), it always returns 11 for all buttons. Can anyone help me figure out the correct ...

What is the correct method for creating text that adjusts to different screen sizes?

It's common for designers to provide me with responsive designs that adjust the text of an element depending on the screen size. On Desktop: Read more On Mobile: Read On Desktop: Download PDF On Mobile: Export On Desktop: Click here On Mobile ...

org.codehaus.jackson.JsonParseException: An unexpected character ("/" (code 47)) appeared

I have a file with a customer list stored as a HashMap in json format. Here is an example: {"John":{"name":"John","id":"12345", "email":"john@test.com","phone":"555-555-5555"}} This represents just one customer from the list. When the controller is ...

Find a match by comparing a field only with arrays that contain at least one element

I'm currently working on a filtering system. Let me show you a simple version of my Order model: { merchant: <Reference to the merchant>, date: <Date Object> name: "Some order name", ingredients: [{ ingred ...

Implementing dynamic routes with Nuxt.js

I encountered an issue while working on deploying my Nuxt.js page to Netlify. Everything went smoothly except for the dynamic pages I had created. Below is a snippet from my nuxt.config.js file: import axios from 'axios' let dynamicRoutes = () = ...

Learn how to securely transmit data using basic authentication in Node.js with the node-fetch module

Having trouble with this code. I am facing an issue where a "post" request with basic authentication returns a 200 status, but no response data is received. Surprisingly, when the same code is executed without auth credentials, it works perfectly fine. l ...

What is the best way to show an SVG icon in React without having to make an HTTP request for the file?

A special requirement for a react application is to display icons in certain parts of the application while offline. The use of inline svg is particularly fitting for this purpose. import React from 'react'; // Utilizing inline svg to showcase i ...

Tips for utilizing GSON and showcasing data in a JSP document

I am in the process of building a web application using JSP. One of the servlet classes I have created is as follows: package managesystem; import java.util.List; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; impor ...

Creating a database using Angular2+ in CouchDB can be achieved by following these steps

I have been attempting to set up a database in couchdb using angular2+. My goal is to create a button that, when clicked, will initiate the creation of the database. However, I keep encountering an error message. "ERROR Error: Uncaught (in promise): H ...

Use jQuery to open and close HTML tags efficiently

It seems like the task I have at hand may not be as simple as I had hoped, so here I am seeking some reassurance. I am aiming to switch out an image with a closing div, then the image itself, followed by another opening div. Let me illustrate this with a ...

Getting the Featured Image from a Post Link in Wordpress: A Step-by-Step Guide

For my Wordpress project, I have a group of links leading to inner pages, each with their own featured image. These links are created using the menu feature in Wordpress. My goal is to allow users to click on these links and have the featured image from t ...

What is the data type of the JSON file content in the R programming language?

I'm working with a JSON file saved on my local machine. I am curious about the data structure of the output. Will it be a dictionary, list, or string? Here is the code snippet from my Rstudio: install.packages("rjson") library("rjson") output <- f ...

How can a Grid view be displayed within a Modal PopUp Extender?

I am currently working on a mapping application using ASP.net C#. Within my application, I have implemented a textbox and button that searches a database based on postcode and displays the results in a Grid view on my aspx page... public partial class _D ...

What causes AJAX to disrupt plugins?

I am facing a challenge with my webpage that utilizes AJAX calls to load content dynamically. Unfortunately, some plugins are encountering issues when loaded asynchronously through AJAX. I have attempted to reload the JavaScript files associated with the ...

Loading of iframes occurs only after receiving the content sent through the postMessage function

I have a scenario where an iframe is used to receive information through the contentWindow.postMessage function in order to log in to a page that I am creating. However, I am facing an issue where the page loads before the contentWindow.postMessage message ...

Using Try and Catch effectively - tips and strategies

As I delve into learning JavaScript on my own, one topic that caught my attention is the try/catch structure. The tutorial I came across only covers how to implement it, but lacks in explaining its practical applications. Is there anyone who can shed som ...

Exploring a one-dimensional nested array in order to make updates to the higher level nodes

I have a 1D nested array: nestedArr: [ { id: 1, parentId: null, taskCode: '12', taskName: 'Parent', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []}, { id: 2, parentId: 1, taskCo ...

Show the decoded JSON dictionary values in a SwiftUI Text() without relying on a List

I'm completely new to SwiftUI, but I've managed to create a functional Help Desk app. In the primary Content View, I have successfully retrieved all tickets from a JSON link and displayed that limited data in a list of all tickets. Clicking on a ...

The inability to utilize the "require" function in a distinct JavaScript file within Electron

My Electron app is quite simple, using version 5.0.1. Below is the content of my index.html: <!DOCTYPE html> <html> <head> <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> <meta co ...