json-server icon indicating copy to clipboard operation
json-server copied to clipboard

SyntaxError: Unexpected token '', "{ "pos"... is not valid JSON

Open ligteltelecom opened this issue 1 year ago • 2 comments

Hi can anyone help me with this issue ?

D:\projetos_angular\frontend>npx json-server db.json
<anonymous_script>:1
{
^

SyntaxError: Unexpected token '', "{
  "pos"... is not valid JSON
    at JSONFile.parse (<anonymous>)
    at JSONFile.read (file:///D:/projetos_angular/frontend/node_modules/lowdb/lib/adapters/node/DataFile.js:17:31)
    at async Observer.read (file:///D:/projetos_angular/frontend/node_modules/json-server/lib/observer.js:21:22)
    at async Low.read (file:///D:/projetos_angular/frontend/node_modules/lowdb/lib/core/Low.js:16:22)
    at async file:///D:/projetos_angular/frontend/node_modules/json-server/lib/bin.js:114:1

Node.js v22.14.0

D:\projetos_angular\frontend>

db.json below:

{ "posts": [ { "id": "1", "title": "a title" }, { "id": "2", "title": "another title" } ], "comments": [ { "id": "1", "text": "a comment about post 1", "postId": "1" }, { "id": "2", "text": "another comment about post 1", "postId": "1" } ], "profile": { "name": "typicode" } }

ligteltelecom avatar Feb 14 '25 10:02 ligteltelecom

Using json-server version "0.17.4" working fine npm i [email protected]

ligteltelecom avatar Feb 14 '25 11:02 ligteltelecom

You might be using a file encoded in "UTF-8 with BOM." Try changing the encoding (for example, using Notepad++) to normal "UTF-8" encoding.

Iworb avatar May 06 '25 14:05 Iworb