How to write one key value pair per line from python dict to a json file?

Viewed 1037

I am trying to write a python dict to a json file

My dict entries look like the following

When I use json.dumps to write my dict to a json file, my json file looks like the following

{
     "sheen": [
              [
                   318,
                   1
              ],
              [
                   518,
                   1
              ],
              [
                   94,
                   1
              ]
}

But what I want is,

{
 "sheen" : [[318,1],[518,1],[94,1]]
 "sheen2": [[313,1],[538,1],[91,1]]
}

i.e one key and value set per line

As of now the values are going the next line

Is there any way in which I can achieve what I want to do ?

Edit:

Here is the function that I am using to write the file

def dict_to_json_file(dict, file_name):

    with open(file_name, 'w') as fp:
        json.dump(dict, fp, indent = 4);
0 Answers
Related