Unexpected token in JSON.parse

I use node and request js for getjson object from third party api. When I try to parseget data, I get an error message:

SyntaxError: Unexpected token

Then I tried to analyze the data in my external application, which led to the following error (see the space after the token):

SyntaxError: Unexpected token in JSON at position 294512

So, I tried to run it through Postman and see what happened. The returned JSON seems valid, and I also ran it through the JSON validator without any problems.

After examining the result a little more, I found that one attribute (Document Type) always had a space inside double qoutes:

{
"F24434": {
    "Posting Date": "29-10-12",
    "Open": "No",
    "On Hold": "",
    "Document Type": " ",
    "External Document No.": "",
    "Due Date": "29-10-12",
    "Description": "xxxx",
    "Order No.": "",
    "Currency Code": "DKK",
    "Remaining Amount": "0",
    "Original Amount": "0",
    "Amount": "0",
    "User ID": "xxx",
    "Systemdato": "29-10-12",
    "Entry No.": "607121",
    "Vessel No.": "",
    "Port No.": ""
  }
}

I'm not sure if this caused a problem or could there be something else?

Unfortunately, I do not have direct access to the API, so I cannot change the way data is structured.

, . , :

.replace(/\s/g, '');

+4

Source: https://habr.com/ru/post/1664421/


All Articles