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

Unexpected token '�', "��{ | "... is not valid JSON #90

Closed stephanvdplas closed 1 year ago

stephanvdplas commented 1 year ago

Allthough I follow the exact examples in the readme file, I receive this error:

0|mm | [10.08.2023 12:51.58.234] [ERROR] (node:7568) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '�', "��{ 0|mm | "... is not valid JSON 0|mm | at JSON.parse () 0|mm | at Response.json (file:///home/pi/MagicMirror/modules/MMM-JsonTable/node_modules/node-fetch/src/body.js:149:15) 0|mm | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 0|mm | (Use electron --trace-warnings ... to show where the warning was created) 0|mm | [10.08.2023 12:51.58.235] [ERROR] (node:7568) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

The issue is in the URL format: 'https://server.vdplas.net:8083/thuis.json' . Because when entering 'https://[jsonplaceholder.typicode.com/users](https://jsonplaceholder.typicode.com/users)' it works perfectly, the table is shown, but when entering the former URL, even when there is the exact same file located, it does not work.

What is wrong in the format? Is it the : ?

stephanvdplas commented 1 year ago

Nevermind. After rebooting my pi, it has been resolved.

stephanvdplas commented 1 year ago

Without changing anything (afaik), this issue returned.

Here the module config in the config.js:

        {
            module: 'MMM-JsonTable',
            position: 'bottom_right',
            header: 'Aanwezig',
            config: {
                url: 'https://server.vdplas.net:8083/thuis.json', // Required
                arrayName: 'items', // Optional
                tryFormatDate: false,
            }
        },

And this is the (anonymized) json, found internally on my network at https://server.vdplas.net:8083/thuis.json

{
    "items":  [
                  {
                      "icon":  "fa-person-walking",
                      "name":  "XXX",
                      "aanwezig":  "is weg sinds",
                      "lastUpdate":  "10-8-2023 11:22:22"
                  },
                  {
                      "icon":  "fa-person-walking",
                      "name":  "YYY",
                      "aanwezig":  "is weg sinds",
                      "lastUpdate":  "12-8-2023 04:47:57"
                  },
                  {
                      "icon":  "fa-home",
                      "name":  "ZZZ",
                      "aanwezig":  "is thuis sinds",
                      "lastUpdate":  "12-8-2023 04:48:10"
                  }
              ]
}

What can be the cause of this issue?

KristjanESPERANTO commented 1 year ago

Which character encoding does your file have? Run file -bi [filename] to check.

stephanvdplas commented 1 year ago

It must have been something in de file encoding. I completely recreated the file withe the -Encoding ascii parameter ($myJson | ConvertTo-Json -Depth 2 | Out-File $filename -Encoding ascii) Now it works!