Home > Enterprise >  Python Append to List of Json?
Python Append to List of Json?

Time:04-21

In python I'm trying to create .json file like this:

dic = {"vendor": "test", "username": "", "password": "", "connection": {"type": "telnet"}}

The output is:

[
  {
    'vendor': 'test',
    'username': '',
    'password': '',
    'connection': {
      'type': 'telnet'
    }
  }
]

How can I force python to use " instead of ', for example I don't want this:

'vendor': 'test',

But this:

"vendor": "test",

CodePudding user response:

It depends on the library you're using. Try using Python json built-in library:

import json 

dic = {"vendor": "test", "username": "", "password": "", "connection": {"type": "telnet"}}

out = json.dumps(dic)

out

Does it work for you?

CodePudding user response:

You can use try this

import json

dic = {"vendor": "test", "username": "", "password": "", "connection": {"type": "telnet"}}

print(json.dumps(dic))
  • Related