Why this JSON object cannot be parsed?

parse json
how to fix json parse error
get value from json object in javascript
json.parse invalid character
json.parse error handling
javascript parse json array
json.parse browser support
json.parse array of objects

In my JavaScript file,

The declaring and json parse for the ajax response text is like this:

var subcats = JSON.parse(this.responseText);

The supposed responseText for the parsing is like this:

{"presubcatId":"1","precatId":"1","presubcatName":"HR Manager"}{"presubcatId":"2","precatId":"1","presubcatName":"Marketing Manager"}

and it gives me this error:

SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 64 of the JSON data

what's the syntax error? help

Your JSON have multiple elements and therefore should be wrap in an Array/List like this

[{"presubcatId":"1","precatId":"1","presubcatName":"HR Manager"}{"presubcatId":"2","precatId":"1","presubcatName":"Marketing Manager"}]

Hope it helps

SyntaxError: JSON.parse: bad parsing, The JavaScript exceptions thrown by JSON.parse() occur when string failed to name in object SyntaxError: JSON.parse: end of data after property value in object You cannot use single-quotes around properties, like 'foo'. JSON.parse throws if invoked with invalid JSON and this can cause strange bugs. This problem happens often especially with the preponderance of JavaScript frameworks. At least, I have run into it while using Angular1 and Angular2.

Your JSON is invalid. You need change it like this:

[{"presubcatId":"1","precatId":"1","presubcatName":"HR Manager"},{"presubcatId":"2","precatId":"1","presubcatName":"Marketing Manager"}]

JavaScript JSON parse() Method, The function is called for each item. Any nested objects are transformed before the parent. If the function returns a valid value, the item value is replaced with the​  "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error". could give me the solution ? my json data format from server. but my data comes in body. i could not display the data in table. could you help me?

your JSON data is invalid so that you are having problem,

var temp=[];
temp=[{"presubcatId":"1","precatId":"1","presubcatName":"HR Manager"},{"presubcatId":"2","precatId":"1","presubcatName":"Marketing Manager"}]


jQuery.parseJSON(), jQuery.parseJSON( json )Returns: String or Number or Object or Array or To parse JSON strings use the native JSON.parse method instead. Passing "​undefined" ( undefined cannot be represented in a JSON string; null , however, can be). "JSON data from server cannot be parsed. This is caused by JSON formatting error" warning. Apr 21, 2011 10:47 AM "JSON data from server cannot be parsed. This is

Your JSON have multiple elements. So it must be treated like Array. See below image.

Below is valid JSON structure.

[{"presubcatId":"1","precatId":"1","presubcatName":"HR Manager"},{"presubcatId":"2","precatId":"1","presubcatName":"Marketing Manager"}]

not able to parse JSON file,parsing a json, jsonfile.jpg as attached in the image, i am able to parse the JSON and I think you are trying to treat the "very long string" as a JSON object, but it's not. i am trying to parse the last string it says "cannot parse a string which  A common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object.

The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. So you can use it like this if you have a single item:

JSON.parse('{"presubcatId":"1", "precatId":"1", "presubcatName":"HR Manager"}');

but in your case you have multiple items that should be wrapped inside brackets [] and separated by commas or there is SyntaxError:

JSON.parse('[{"presubcatId":"1", "precatId":"1", "presubcatName":"HR Manager" }, { "presubcatId": "2", "precatId": "1", "presubcatName": "Marketing Manager"}]');

var string = '[{"presubcatId":"1", "precatId":"1", "presubcatName":"HR Manager" }, { "presubcatId": "2", "precatId": "1", "presubcatName": "Marketing Manager"}]';

var json = JSON.parse(string);


Parse JSON Formatted Logs, Allows you to extract values from JSON input. For details, see parse field. auto - automatically detects JSON objects in logs and extracts the key/value pairs. See JSON auto unable to parse json warning message.png. Also I really recommend you to use JSON deserialization library, such as Gson or JacksonJSON (FasterXML), because you'll need to do manually type checking and object parsing, which is unnecessary overhead.

Error while converting JSON object to TW object - Forums, I am trying to convert a JSON object to TW object using below mentioned code. //​var jsonObject = JSON.parse(tw.local.data);. //if(jsonObject.personalDetails). Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

JSONObject, Values may not be null , Double#isNaN() , Double#isInfinite() , or of any JSONException, if the parse fails or doesn't yield a JSONObject . JSON.parse(text[, reviver]) Parameters text The string to parse as JSON. See the JSON object for a description of JSON syntax. reviver Optional If a function, this prescribes how the value originally produced by parsing is transformed, before being returned. Return value. The Object corresponding to the given JSON text. Exceptions

Cannot parse json object with two keys. Unexpected token expected , Bug Report Current Behavior We want to use babel/parser to extrac the strings in my code to auto localization. I write my own html parse to get  Parsing generally means interpreting. JSON is a format specification as mentioned by the rest. Parsing JSON means interpreting the data with whatever language u are using at the moment.

  • Yes, that is not a valid JSON string (or a string at all). You can read the spec here.
  • Run it through jsonlint, the error stands out instanly.
  • I guess it should look like this [{"presubcatId":"1","precatId":"1","presubcatName":"HR Manager"},{"presubcatId":"2","precatId":"1","presubcatName":"Marketing Manager"}]
  • Yes got that. I fetched data by rows which caused Invalid parse I think. Now I tried fetch all method it was okay.