Weird Error when trying to code a todo app - javascript

Just playing with JavaScript and I got an error an Uncaught SyntaxError: Unexpected token D in JSON at position 0
at JSON.parse ()
at app.js:22
The code in my JavaScript file error line is:
if (data) {
LIST = JSON.parse("TODO");
} else {
}

JSON.parse() will only work on strings or string variables that represent a JSON object, like
"
'item1': 50,
'item2': 80,
'item3': 100
"
in order to parse them into JSON objects
As you can tell, "TODO" cannot be parsed into a JSON object, but perhaps in your code there is a variable data which is a string representing JSON object. Most likely you will need to change that line to:
LIST = JSON.parse(data);

You are using json.parse on wrong data type.json.parse is made for objects while you are passing a string JSON.parse("TODO"). Note that "TODO" is a string and not an object.
Follow this example:
const todo = '{"name":"Empty the trash"}'
const obj = JSON.parse(todo);

Related

Converting string to object with Javascript (Error: Unexpected token t in JSON at position 1)

I'm using Editor.js which outputs data as JSON and save that as String in DynamoDB. When I query that data, I want to convert that back to an Object.
Converting the string with JSON.parse() gives me Error: Unexpected token t in JSON at position 1 message.
var json = '{time=1558311121067, blocks=[{type=paragraph, data={text=writing something first}}], version=2.13.0}';
obj = JSON.parse(json);
Not sure what this error message means.
I will suggest to correct the JSON from the origin itself if you can,
if you can't than you need to replace = with : and than stringify and parse
({[^=]+|,[^=]+)=
| |_________ Replaces `=` which is preceded by `,`
|_________________ Replaces `=` which is preceded by `{`
let json = '{time=1558311121067, blocks=[{type=paragraph, data={text=writing something first}}], version=2.13.0}';
json = json.replace(/({[^=]+|,[^=]+)=/g,"$1"+':')
let obj = JSON.parse(JSON.stringify(json));
console.log(obj)
On side note:- This is code is considering above given example data, it can be updated based on the kind of values your JSON can have

Why does JSON.parse give invalid character

Edit: Solved... I needed to use JSON.stringify() here. Doh.
I am trying to JSON.parse() a response token and keep getting "SyntaxError: Invalid character" in Internet Explorer. (Not sure if this issue is present in Chrome due to CORS, but that's a different issue.)
console.log(response.token.isAdmin)
// false
console.log(JSON.parse(response.token.isAdmin))
// false
console.log(response.token.tokenValue)
// 36151b9e-ad0d-49de-a14b-5461489c7065
console.log(JSON.parse(response.token.tokenValue.toString()))
// SyntaxError: Invalid character
The same error occurs for any string I am trying to parse. If the source is not a string (boolean, integer) the parsing works fine.
Why isn't this working and how can I put my object into a string?
36151b9e-ad0d-49de-a14b-5461489c7065 is invalid JSON.
JSON.parse('36151b9e-ad0d-49de-a14b-5461489c7065'); // SyntaxError
Maybe you meant "36151b9e-ad0d-49de-a14b-5461489c7065", which is valid JSON.
JSON.parse('"36151b9e-ad0d-49de-a14b-5461489c7065"');
// 36151b9e-ad0d-49de-a14b-5461489c7065
Or maybe you wanted to stringify to JSON instead of parse
JSON.stringify('36151b9e-ad0d-49de-a14b-5461489c7065');
// "36151b9e-ad0d-49de-a14b-5461489c7065"
It appears that you are trying to parse a string that is not valid JSON.
You could parse a string like this:
var parseMe = '{ "tokenValue": "36151b9e-ad0d-49de-a14b-5461489c7065" }';
var parsed = JSON.parse(parseMe);
// parsed is now equal to Object {tokenValue: "36151b9e-ad0d-49de-a14b-5461489c7065"}
But you cannot parse something that is not formatted as JSON, like this:
var parseMe = '36151b9e-ad0d-49de-a14b-5461489c7065';
var parsed = JSON.parse(parseMe);
// Uncaught SyntaxError: Unexpected token b in JSON at position 5
If instead you wanted to get a JSON object parsed as a string, you could use JSON.stringify() like so:
var stringifyMe = { tokenValue: '36151b9e-ad0d-49de-a14b-5461489c7065' };
var stringified = JSON.stringify(stringifyMe);
// stringified is now equal to the string {"tokenValue":"36151b9e-ad0d-49de-a14b-5461489c7065"}

Javascript JSON parse and stringify for multi levels

I have a javascript object that contains a property with values of another json stringified object. I cannot get the printout version of the string back to object form. See the following code. the console.log output content of json string is exactly as right side of jsonFromStr. However, JSON.parse(json) is OK, while JSON.parse(jsonFromStr) is error. What is wrong here?
jsfiddle: http://jsfiddle.net/jma7889/qtmmpj2t/
level2Obj = { key2a: "foo", key2b: 3};
level2ObjJson = JSON.stringify(level2Obj);
level1Obj = {key1a: "bar", key1b: {level2ObjJson}};
json = JSON.stringify(level1Obj);
jsonFromStr = '{"key1a":"bar","key1b":{"level2ObjJson":"{\"key2a\":\"foo\",\"key2b\":3}"}}'; // same than json
objFromStrify = JSON.parse(json); // OK
objFromAssignedString = JSON.parse(jsonFromStr); // Uncaught SyntaxError: Unexpected token l in JSON at position 45
If you do this it will work:
jsonFromStr = '{"key1a":"bar","key1b":{"level2ObjJson":"{\\\"key2a\\\":\\\"foo\\\",\\\"key2b\\\":3}"}}';
The reason that your version does not work is that the escape sequence \" is resolved at that very moment, and so the actual value of jsonFromStr will be:
'{"key1a":"bar","key1b":{"level2ObjJson":"{"key2a":"foo","key2b":3}"}}'
... which is invalid JSON.
You need to keep those escapes unresolved in the JSON string, and this you do by escaping the escape sequence itself with additional slashes.
jsonFromStr = '{"key1a":"bar","key1b":{"level2ObjJson":{\"key2a\":\"foo\",\"key2b\":3}}}';
You have an extra "" for value of level2ObjJson key,replace jsonFromStr in your code with the above code .

SyntaxError: JSON Parse error: Unexpected EOF

I have the following line of code:
data = jQuery.parseJSON(data);
Which is creating the following error...
SyntaxError: JSON Parse error: Unexpected EOF
I can't work out how to identify what's causing the error though.
Any ideas?
Here's the data...
{
"element_type": "paint",
"edit_element_id": "2117",
"paint_id": "15",
"paint_editable_data": "zwibbler3.[{\"id\":0,\"type\":\"GroupNode\",\"fillStyle\":\"#cccccc\",\"strokeStyle\":\"#000000\",\"lineWidth\":2,\"shadow\":false,\"matrix\":[1,0,0,1,0,0],\"layer\":\"default\"},{\"id\":1,\"type\":\"PageNode\",\"parent\":0,\"fillStyle\":\"#cccccc\",\"strokeStyle\":\"#000000\",\"lineWidth\":2,\"shadow\":false,\"matrix\":[1,0,0,1,0,0],\"layer\":\"default\"},{\"id\":2,\"type\":\"BrushNode\",\"parent\":1,\"fillStyle\":\"#cccccc\",\"strokeStyle\":\"#000000\",\"lineWidth\":10,\"shadow\":false,\"matrix\":[1,0,0,1,0,0],\"layer\":\"default\",\"points\":[17,21,17,22,17,24,17,28,18,34,37,55,49,59,70,61,89,56,92,55,93,54]},{\"id\":3,\"type\":\"PathNode\",\"parent\":1,\"fillStyle\":\"#e0e0e0\",\"strokeStyle\":\"#000000\",\"lineWidth\":2,\"shadow\":false,\"matrix\":[1,0,0,1,-14,-85],\"layer\":\"default\",\"textFillStyle\":\"#000000\",\"fontName\":\"Arial\",\"fontSize\":20,\"dashes\":\"\",\"smoothness\":0.3,\"sloppiness\":0,\"closed\":true,\"arrowSize\":0,\"arrowStyle\":\"simple\",\"doubleArrow\":false,\"text\":\"\",\"roundRadius\":0,\"commands\":[0,150,100,6,200,150,200,100,6,150,200,200,200,6,100,150,100,200,6,150,100,100,100,7],\"seed\":36934}]",
"paint_image_data": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALwAAAB1CAYAAAD0rovXAAASHklEQVR4Ae1dCXBW1RW+BAKJNAwihMWgkYkN+1JgRGAEBKQtISIVcBoQRGiKhBadQXQ07XQoVhwQtLiwVGSzUEAgwGgAIVgMyCbLsAlllzVSFSmLhPT7Hv/LvCwk77285V/Omfly33Lfued+9+T+d3v3KSUiDAgDwoAwIAwIA8KAMCAMCAPCgDAgDAgDwoAwIAwIA8KAMCAMCAPCgDAgDAgDwoAwIAwIA8KAMCAMCAPCgDAgDAgDwkA4M1ApnDMneSuTgXtwt34A9QzH+jU9pJKzpeBcsWvfMmKwizh8sJeQc/YlQ1VXoFsgrIvQSTkPZTkBbEB4CAg6sevwlZGTjkBqAMxYVgC5CPN5QcRXBqKR+iPA4wHcZ7QmNjZW1a1bV8XHx2th8WP9nM9cuHBBnT9/vhDGc/346tWrRvU8PgmsCOBzhD8Bvotdh38flqffwfrpuP77O9yTy+4zkIQkRgDPAHX05GrXrq06dOigOnbsqIWNGjXSbzkSHj16VG3ZskXl5uZqYV5enlHvRZzMBmYCR4w3vD624/CPwcjscgzthftryokjt51loDXUvQr0A7RyTUpKUr169dLQsmVLZ1MrR9uePXtUdna2hiNHCn28AI99DPwV2FWOCldu23H4HFjSpRxrNuJ+13LiyG1nGGgGNeOBJ6guJiZGpaamqsGDB6sW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4JkBXJDTFegWCJ1einkeenMC2IAwKDfEF4dHyUSo3IN81w+gnuFYv6aHpOdsKThX7BrfQBIRBoSBYGLg/9jYtJnVySp3AAAAAElFTkSuQmCC"
}
Is it the size that's the problem maybe?
It looks like you are trying to convert a text string into a JSON data object.
You should probably be doing the following:
instead of using jQuery.parseJSON(data), rather just use JSON.parse(data).
The error you mentioned indicates you are passing in an empty string "" as your value of data. So check the value that is being passed in to the parse method.
The data object you mentioned that you are passing in will always result in an error since it's already in a JSON format.
The parse method is intended to do the following conversion.
JSON.parse("{\"hello\":\"world\"}") returns {hello:'world'}
If you are trying to convert in an object into a string, you can try this:
JSON.stringify({hello:'world'}) returns "{\"hello\":\"world\"}"
The reason is simple. When you define the JSON in the script, the double quotes should be represented by \" , not " .
In my case i was also facing that same error in React-native but after look into my code i found that .. .my API hit URL was not complete .. and after that.. my problem was resolved :)
Maybe you can do with the eval method :
if (data !== null) {
var json_obj= eval("("+data+")"); //jQuery.parseJSON(data);
//just for check the the keys
var keys = Object.keys(json_obj);
for (var i = 0; i < keys.length; i++) {
console.log(keys[i]);
};
}

putting json into javascript variable

I want to put a JSON object into a javascript variable as a sting in order to create a graph.
qm.createGraphData = function() {
$.post("ajax_getGraphDataWebsite ", function(json) {
qm.negativesData = json;
},"json");
qm.data = [{
"xScale":"ordinal",
"comp":[],
"main":[{
"className":".main.l1",
qm.negativesData},{
"className":".main.l2",
qm.negativesData}],
"type":"line-dotted",
"yScale":"linear"}];
}
the string value should be added to the "data" section. Now the object get's added but I need to add the string value to the variable like the sample below:
{"data":[{"x":"3283581","y":"2013-10-16"},{"x":"1512116","y":"2013-10-17"},{"x":"3967","y":"2013-10-18"},{"x":"1094","y":"2013-10-19"},{"x":"853","y":"2013-10-20"},{"x":"1205","y":"2013-10-21"},{"x":"2618700","y":"2013-10-22"},{"x":"3928291","y":"2013-10-23"},{"x":"3670318","y":"2013-10-24"},{"x":"3347369","y":"2013-10-25"},{"x":"2525573","y":"2013-10-26"},{"x":"3224612","y":"2013-10-27"},{"x":"3992964","y":"2013-10-28"},{"x":"3949904","y":"2013-10-29"},{"x":"3568618","y":"2013-10-30"},{"x":"3104696","y":"2013-10-31"},{"x":"3246932","y":"2013-11-01"},{"x":"2817758","y":"2013-11-02"},{"x":"3198856","y":"2013-11-03"},{"x":"3952957","y":"2013-11-04"},{"x":"3934173","y":"2013-11-05"},{"x":"3878718","y":"2013-11-06"},{"x":"3642822","y":"2013-11-07"},{"x":"3186096","y":"2013-11-08"}]}
This would generate the right graph for me. Does anyone know how to convert the json object into a string like above and to send it to the qm.negativesData variable?
// UPDATE
Now I've got the string with the qm.negativesData = JSON.stringify(json); solution
But my qm.negativesdata won't get added to the qm.data variable... i'm getting a console error SyntaxError: invalid property id
I suppose i'm not adding them the right way?
To convert a JSON object into a JSON string, you can try myObject.stringify(), JSON.stringify(myObject), or if you are using a library using the built in function of that library.
So, you could do something like: qm.negativesData = myObject.stringify()
Cheers

Categories