timdows / MMM-JsonTable

A module for the MagicMirror project which creates a table filled with a list gathered from a json request.
MIT License
25 stars 31 forks source link

JSON syntax error #15

Closed aurely89 closed 3 years ago

aurely89 commented 3 years ago

Hi @timdows , I've tried to solve this for two days by now but with no luck.

Hope you can help since I can't really see where the problem with position 5 is.

From console log I have this error:

[2020-09-23 16:08:12.958] [LOG]    http://192.168.1.50/home/pi/MagicMirror/modules/MMM-JsonTable/prova.json
[2020-09-23 16:08:12.967] [ERROR]  Whoops! There was an uncaught exception...
[2020-09-23 16:08:12.968] [ERROR]  SyntaxError: Unexpected token < in JSON at position 5
    at JSON.parse (<anonymous>:null:null)
    at Request._callback (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:14:21)
    at Request.self.callback (/home/pi/MagicMirror/node_modules/request/request.js:185:22)
    at Request.emit (events.js:200:13)
    at Request.<anonymous> (/home/pi/MagicMirror/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:200:13)
    at IncomingMessage.<anonymous> (/home/pi/MagicMirror/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:288:20)
    at IncomingMessage.emit (events.js:205:15)
    at endReadableNT (_stream_readable.js:1154:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)

[2020-09-23 16:08:12.971] [ERROR]  MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
[2020-09-23 16:08:12.972] [ERROR]  If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues

This is the config array:

        {
            module: 'MMM-JsonTable',
            position: 'top_right',
            header: 'Dati ultima corsa',
            config: {
                    url: 'http://192.168.1.50/home/pi/MagicMirror/modules/MMM-JsonTable/prova.json',
                    arrayName: "items",
                    tryFormatDate: true
                    }

While this is the JSON content (UTF encoded, no BOM characters):

{
    "items": [
        {
            "name":"Data",
            "value":"20/9/20"
        },
        {
            "name":"Distanza",
            "value":"10 Km"
        },
        {
            "name":"Durata",
            "value":"0:52:30"
        },
        {
            "name":"Passo",
            "value":"0:5:15"
        },
        {
            "name":"VDOT",
            "value":"38"
        }
        ]
}

Thank you in advance for your precious support.

Flavio

timdows commented 3 years ago

Good check already on BOM and UTF, as the stack trace indicates the issue is in

var json = JSON.parse(body);

Can you supply the output for some vars over there by adding console.log('debug', error, response, body); on line 13 https://github.com/timdows/MMM-JsonTable/blob/master/node_helper.js#L13

aurely89 commented 3 years ago

Sure, here it is the console log:

[2020-09-24 14:33:40.830] [ERROR]  Whoops! There was an uncaught exception...
[2020-09-24 14:33:40.831] [ERROR]  ReferenceError: error is not defined
    at Class.getJson (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:11:24)
    at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:25:9)
    at Socket.<anonymous> (/home/pi/MagicMirror/js/node_helper.js:112:11)
    at Socket.emit (events.js:200:13)
    at /home/pi/MagicMirror/node_modules/socket.io/lib/socket.js:528:12
    at processTicksAndRejections (internal/process/task_queues.js:82:9)

[2020-09-24 14:33:40.849] [ERROR]  MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
[2020-09-24 14:33:40.851] [ERROR]  If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
[2020-09-24 14:33:41.980] [INFO]   Checking git for module: MMM-JsonTable
Username for 'https://github.com': Username for 'https://github.com': [2020-09-24 14:33:46.006] [LOG]    starting network connection testing
[2020-09-24 14:33:51.634] [ERROR]  Whoops! There was an uncaught exception...
[2020-09-24 14:33:51.636] [ERROR]  ReferenceError: error is not defined
    at Class.getJson (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:11:24)
    at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:25:9)
    at Socket.<anonymous> (/home/pi/MagicMirror/js/node_helper.js:112:11)
    at Socket.emit (events.js:200:13)
    at /home/pi/MagicMirror/node_modules/socket.io/lib/socket.js:528:12
    at processTicksAndRejections (internal/process/task_queues.js:82:9)

[2020-09-24 14:33:51.641] [ERROR]  MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
[2020-09-24 14:33:51.642] [ERROR]  If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
[2020-09-24 14:34:06.021] [ERROR]  Whoops! There was an uncaught exception...
[2020-09-24 14:34:06.022] [ERROR]  ReferenceError: error is not defined
    at Class.getJson (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:11:24)
    at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:25:9)
    at Socket.<anonymous> (/home/pi/MagicMirror/js/node_helper.js:112:11)
    at Socket.emit (events.js:200:13)
    at /home/pi/MagicMirror/node_modules/socket.io/lib/socket.js:528:12
    at processTicksAndRejections (internal/process/task_queues.js:82:9)

[2020-09-24 14:34:06.023] [ERROR]  MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
[2020-09-24 14:34:06.024] [ERROR]  If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues

[2020-09-24 14:34:21.840] [ERROR]  Whoops! There was an uncaught exception...
[2020-09-24 14:34:21.840] [ERROR]  ReferenceError: error is not defined
    at Class.getJson (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:11:24)
    at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:25:9)
    at Socket.<anonymous> (/home/pi/MagicMirror/js/node_helper.js:112:11)
    at Socket.emit (events.js:200:13)
    at /home/pi/MagicMirror/node_modules/socket.io/lib/socket.js:528:12
    at processTicksAndRejections (internal/process/task_queues.js:82:9)

[2020-09-24 14:34:21.842] [ERROR]  MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
[2020-09-24 14:34:21.843] [ERROR]  If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
timdows commented 3 years ago

Wait, I just see your url

http://192.168.1.50/home/pi/MagicMirror/modules/MMM-JsonTable/prova.json

Is this really working? Can you supply the raw output (show it in dev console of a broswer)?

What if you supply the following configuration

module: 'MMM-JsonTable',
position: 'top_right',
config: {
  url: 'https://jsonplaceholder.typicode.com/users',
  keepColumns: ['name', 'username']
}
aurely89 commented 3 years ago

Hi @timdows, I've had the same problem with the JSON file on a NAS or on a cloud drive.

I've tried with the config you've sent and the module still displays 'Awaiting json data' but I see a different error on the console log:

[2020-09-25 13:11:30.348] [ERROR]  Whoops! There was an uncaught exception...
[2020-09-25 13:11:30.350] [ERROR]  ReferenceError: error is not defined
    at Class.getJson (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:11:24)
    at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-JsonTable/node_helper.js:25:9)
    at Socket.<anonymous> (/home/pi/MagicMirror/js/node_helper.js:112:11)
    at Socket.emit (events.js:200:13)
    at /home/pi/MagicMirror/node_modules/socket.io/lib/socket.js:528:12
    at processTicksAndRejections (internal/process/task_queues.js:82:9)

[2020-09-25 13:11:30.353] [ERROR]  MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
[2020-09-25 13:11:30.354] [ERROR]  If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
timdows commented 3 years ago

Of course try that config with the original node_helper.js file

aurely89 commented 3 years ago

Oh, sure. It is correctly working now, so I guess it was a reachability problem.

Thank you very much @timdows!