Revolucion for Monica
Revolucion for Monica

Reputation: 3306

Expecting 'EOF' error when importing a json file in MongoDB

I am trying to import the following json file into MongoDB with Compass but I get an error:

Unexpected token � in JSON at position 0 while parsing near '�' in C:\Users\antoi\Downloads\restaurants.json 

> 1 | �
| ^

Then I tried to test it from another source but it didn't work:

Error: Parse error on line 10:
...s Park Bake Shop"} { "_id": {        "$oid"
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'

is a quotation mark missing? But when I add a quotation mark it gives me:

Error: Parse error on line 10:
...is Park Bake Shop"}, {   "_id": {        "$oi
----------------------^
Expecting 'EOF', got ','

Upvotes: 2

Views: 537

Answers (1)

Use mongoimport

mongoimport --db myDb --collection restaurants --file restaurants.json

restaurants.json is not a valid JSON, not wrapped in array nor it has commas at the end.

https://docs.mongodb.com/manual/reference/mongodb-extended-json/

Upvotes: 1

Related Questions