Error: Uncaught (in promise): SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data


#1

I am getting the following error:-

this is my console:-



ERROR Error: Uncaught (in promise): SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
HomePage.prototype.loadCheckbook/<@http://localhost:8102/build/main.js:64164:30
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8969
onInvoke@http://localhost:8102/build/main.js:4480:28
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8896
c</r.prototype.run@http://localhost:8102/build/polyfills.js:3:4121
f/<@http://localhost:8102/build/polyfills.js:3:13729
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673

Stack trace:
c@http://localhost:8102/build/polyfills.js:3:13190
f/<@http://localhost:8102/build/polyfills.js:3:13762
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673
  main.js:1436:5
Current account => Untitled  main.js:64057:13
ERROR Error: Uncaught (in promise): SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
HomePage.prototype.loadCheckbook/<@http://localhost:8102/build/main.js:64164:30
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8969
onInvoke@http://localhost:8102/build/main.js:4480:28
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8896
c</r.prototype.run@http://localhost:8102/build/polyfills.js:3:4121
f/<@http://localhost:8102/build/polyfills.js:3:13729
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673

Stack trace:
c@http://localhost:8102/build/polyfills.js:3:13190
f/<@http://localhost:8102/build/polyfills.js:3:13762
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673
  main.js:1436:5
Updating..  main.js:64165:13
Current account => Untitled  main.js:64057:13
ERROR Error: Uncaught (in promise): SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
HomePage.prototype.loadCheckbook/<@http://localhost:8102/build/main.js:64164:30
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8969
onInvoke@http://localhost:8102/build/main.js:4480:28
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8896
c</r.prototype.run@http://localhost:8102/build/polyfills.js:3:4121
f/<@http://localhost:8102/build/polyfills.js:3:13729
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673

Stack trace:
c@http://localhost:8102/build/polyfills.js:3:13190
f/<@http://localhost:8102/build/polyfills.js:3:13762
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673
  main.js:1436:5
ERROR Error: Uncaught (in promise): SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
HomePage.prototype.loadCheckbook/<@http://localhost:8102/build/main.js:64164:30
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8969
onInvoke@http://localhost:8102/build/main.js:4480:28
f</t.prototype.invoke@http://localhost:8102/build/polyfills.js:3:8896
c</r.prototype.run@http://localhost:8102/build/polyfills.js:3:4121
f/<@http://localhost:8102/build/polyfills.js:3:13729
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673

Stack trace:
c@http://localhost:8102/build/polyfills.js:3:13190
f/<@http://localhost:8102/build/polyfills.js:3:13762
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9644
onInvokeTask@http://localhost:8102/build/main.js:4471:28
f</t.prototype.invokeTask@http://localhost:8102/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8102/build/polyfills.js:3:4812
o@http://localhost:8102/build/polyfills.js:3:1884
t/this.invoke@http://localhost:8102/build/polyfills.js:3:10673
  main.js:1436:5
Updating..

#2

here is the function in main.js which it is pointing to.–

HomePage.prototype.loadCheckbook = function (account) {
        var _this = this;
        this.store.get(account).then(function (data) {
            _this.register = JSON.parse(data) || [];
            console.log("Updating..");
        });
    };

#3

Add a console.log(data) in front of the JSON.parse(data) call. The JSON in data seems to be broken so it can’t parse it.


#4

in this way-

loadCheckbook(account){
		this.store.get(account).then(data => {
			console.log(data);
			this.register = JSON.parse(data) || [];
			console.log("Updating..");
		});

#5

Yes. This should show you what data actually is before you try to parse it. It probably is not in a parseable form.