3

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);
alex
  • 6,818
  • 9
  • 52
  • 103
Athul Muralidharan
  • 693
  • 1
  • 10
  • 18

0 Answers0