1

I have generate several one-liner JSON files(from excel) -which i attempted to read via the cordova mobile app. The file is being read but the problem is parsing it example onliner Json File: Note the file is being read

inside onloadend:

{"name":"Acrobat Ant","id":"500","category":"Ants","features":{"format": {"cn":"hd_lst" ,"fm":"inline","edit": 0},"npma":"1.Ants//13.Wood-infesting Insects","compare2":"","length":"Adults  2.5-4mm // Queen  10mm","color":"Brown to black // "... (this is only partial 

Error in Success callbackId: File899903995 : SyntaxError: Unexpected token   in JSON at position 72
   cordova.js:310 SyntaxError: Unexpected token   in JSON at position 72
    at JSON.parse (<anonymous>)
    at FileReader.reader.onloadend (plugins.js:188)
    at FileReader.readSuccessCallback (plugins/cordova-plugin-file/www/FileReader.js:164)
    at Object.callbackFromNative (cordova.js:291)
    at <anonymous>:1:9

This happens to ever single file i try. That position 72 (for this file) is at the end of the {"format"
word just before the colon : As i said this happens to every other file except the position changes but all fail exactly right at the end of the format property.

I used https://jslint.com/ to check the syntax of the one line JSON and it says is good. The curious thing is that if the one liner is changed to a layered format(via visual Code Shift-ALt-F) as the sample breakdown shown below the JSON gets parse with no problem.

{
        "name": "Acrobat Ant",
        "id": "500",
        "category": "Ants",
        "features": {
            "format": {
                "cn": "hd_lst",
                "fm": "inline",
                "edit": 0
            },
            ....etc

By the way The one line JSON files were generated from Excel and saved as UTF8 Without BOM. (It fails if i try to parse used it WITH BOM.) So My dilemma is That I have over 200 files which I would like them to be read immediately once created without I having to do the manual extra step to turn them into a layered format JSON.

FYI I used exactly the suggestion on how to save excel data to UTF8 without BOM from VBA : save a file with UTF-8 without BOM

please advise

  • Could it be a _No-Break Space_ in `…{"format": {"cn"…` (a neighbourhood of _position 72_)? Maybe `0xA0` is not a valid white space character to use as a separator between tokens? – JosefZ Dec 08 '20 at 20:43
  • How are you creating the JSON? – Tim Williams Dec 09 '20 at 00:24
  • Based on the error message, it seems to be breaking on an invisible character. I'd try opening up the JSON file in a hex editor to determine what exactly what character is at position 72. Might help you trace where the actual problem is. – Norman Breau Dec 09 '20 at 01:26
  • Ok thank you all for the suggestions. Norman and Josef i will use a hexeditor tomorrow when i get a chance and report me findings. Tim, i created it using VBA. I put all the objects(excel colums) together to create one line. I used Jlint to verify is valid json content.. it works if i let my one liner be formatted by visual code. Otherwise it would fail to parse. As i said i will report tomorrrow. Thanks – Dragon Heart Dec 10 '20 at 05:41
  • Update. You both were right as far as the issue being an extra character. Josef indeed that extra space after the colon : was the problem. I am new at using this stackoverflow please let me know if i am supposed to checkmark something to give you credit for the answer... thank you all. -D.H – Dragon Heart Dec 10 '20 at 06:27

0 Answers0