Convert Json Dictionary Objects to Python dicitonary
Question: I have a Json file with dictionary like objects

    
    
    {"d1a": 91, "d1b": 2, "d1c": 1, "d1d": 5, "d1e": 7, "d1f": 77, "d1e": 999}
    {"d2a": 1, "d2b": 2, "d2c": 3, "d2d": 4, "d2e": 5, "d2f": 6, "d2e": 7}
    {"d3a": 1, "d3b": 2, "d3c": 3, "d3d": 4, "d3e": 5, "d3f": 6, "d3e": 7}
    

I want to convert this into a python dictionary with the same format

    
    
    with open(myfile.json, 'r') as myfile:
    # not sure how the conversion will start
    


Answer: If this is how the file contents looks as is, it is not a valid JSON as a
whole, but each line is.

You can read the file _line by line_ and call `json.loads()`:

    
    
    import json
    
    with open(myfile.json, 'r') as myfile:
        for line in myfile:
            print(json.loads(line))
    

And you can have a list of dictionaries if you would use a [list
comprehension](https://docs.python.org/2/tutorial/datastructures.html#list-
comprehensions):

    
    
    objs = [json.loads(line) for line in myfile]
    

You can also call the `loads()` once if you would surround the contents with
`[` and `]` and put commas at the end of each line:

    
    
    with open("test.json") as myfile:
        data = "[" + ",".join(myfile.readlines()) + "]"
        print(json.loads(data))
    

