Friday, August 9, 2019

How to read Mongo JSON in Python

Below is sample code to read Mongo JSON in python code.

Note: Every line have one Object in Mongo JSON

import json
file = open('../data/j.json','r')
jdata=[]
for line in file:
    jdata.append(json.loads(line))
totalSM=0for reportD in jdata:
    print reportD['key1']
    if 'key2' in reportD.keys():
        imD=reportD['key3']
        if '7' in imD:
            totalSM=totalSM+1            print totalSM

No comments:

Post a Comment