0
{
  "id": "APA91bE9N6D9Tp79gv1kUgWLhsCmbKPKJQlzgtr1iGKlL5249bzD5DxySBiaIzDmk7rOAdrWcNcP0ZxPnaj7e6Esc _iGIYJlDte-E1pMO9GME4QufgdQQOIccM2tExMd9L9RsQthR3160KbQeRmtfxW6gvuPXYN0zw",
  "platform": "android",
  "user": ObjectId("545b2833b21e898413de9314"),
  "_id": ObjectId("545b5e76d6be01755625b284"),
  "createdAt": Date(1415274102856),
  "__v": 0
}{
  "__v": 0,
  "_id": ObjectId("545b67c4d6be01755625b2c1"),
  "createdAt": Date(1415276484321),
  "id": "APA91bFRxirYHIko33D1LiHODpBd77IlRhebK4tMRWecFxb5E6nfWSMFarr5mlwmY9bPQP56DGP7cnli4_jOrS8Ynn3Y9w9uaRoESoEPglqR-rA-3phsh8UtSxMC5lNoOqIrohz3hBjzzpCH_vExwo6B5yV6Mb8jyg",
  "platform": "android",
  "user": ObjectId("545b69a5d6be01755625b2d2")
}

Here is the content of the JSON File.

Code which i am using for importing is:

import json

with open("test.json") as json_file:
    json_data = json.load(json_file)
    print(json_data)  
8
  • 1
    That's not JSON: "user" : ObjectId("545b69a5d6be01755625b2d2" ). Commented Nov 26, 2014 at 7:05
  • I was wondering the same. But this is what i got when i dumped the BSON file into JSON format in mongoDB. I'll try to make it if this is the problem. Thanx Commented Nov 26, 2014 at 7:08
  • 1
    you need to explain about your problem for us , if you expect we help you !!! Also as mentioned in above its not a valid JSON file ! Commented Nov 26, 2014 at 7:09
  • It looks like MongoDB query result. You have to handle ObjectId, Date, etc. Commented Nov 26, 2014 at 7:09
  • If that is what MongoDB gives you as "JSON", then others will have stumbled across the same problem and you should be able to find solutions if you add the term "MongoDB" to you search. Commented Nov 26, 2014 at 7:10

2 Answers 2

1

As @Puffin pointed out you need to handle ObjectId, Date etc if you are dumping a MongoDB BSON into JSON and accessing it.

If possible then use pymongo to access MongoDB directly from Python rather than dumping into JSON and accessing the data.

Sign up to request clarification or add additional context in comments.

Comments

1

Your first string is not valid JSON. It is not possible to ingest this directly to JSON parser. What I would do, is to write a preprocessor, which expands the non JSON elements like ObjectId or Date to e.g. strings. Something in the line of this answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.