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)  
Tiny
  • 27,221
  • 105
  • 339
  • 599
Yash Rastogi
  • 465
  • 4
  • 14
  • 1
    That's not JSON: `"user" : ObjectId("545b69a5d6be01755625b2d2" )`. – Ulrich Eckhardt Nov 26 '14 at 07: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 – Yash Rastogi Nov 26 '14 at 07: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 ! – Mazdak Nov 26 '14 at 07:09
  • It looks like `MongoDB` query result. You have to handle `ObjectId`, `Date`, etc. – Puffin GDI Nov 26 '14 at 07: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. – Ulrich Eckhardt Nov 26 '14 at 07:10
  • Maybe you can refer to http://stackoverflow.com/questions/11867538/how-can-i-use-python-to-transform-mongodbs-bsondump-into-json. – Puffin GDI Nov 26 '14 at 07:13
  • @Kasra I'll get in touch with u ... but i'll have torefine my question after some minor changes. – Yash Rastogi Nov 26 '14 at 07:39
  • @YashRastogi ihim , but always attempt to provide a complete describe at your answer , as you explain more as you get complete answer ! – Mazdak Nov 26 '14 at 07:48

2 Answers2

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.

vatsal mevada
  • 5,148
  • 7
  • 39
  • 68
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.

Community
  • 1
  • 1
Joachim Rosskopf
  • 1,259
  • 2
  • 13
  • 24