0

i have a list as follows:

list = [{'option': 'add list'},
         {'ids': ['1', '2', '3']},
         {'option': 'add to log'},
         {'ids': ['1', '5', '6']}]

when output this to file:

with open('list.json', 'w') as outfile:
        json.dump(list, outfile)

it writes the file as:

[{"option": "add list"}, {"ids": ["1", "2", "3"]}, {"option": "add to log"}, {"ids": ["1", "5", "6"]}]

i need to write this to a text file as:

{"option": "add list", "ids": ["1", "2", "3"]}
{"option": "add to log", "ids": ["1", "5", "6"]}

i understand this is not valid json but unfortunately this is the format i need to create for another process. i have looked at the existing answers and they don't give what i need.

Sql_Pete_Belfast
  • 570
  • 4
  • 23

0 Answers0