-2

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",
BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33
Daniel
  • 1
  • 1
  • Does this answer your question? [How to create a Python dictionary with double quotes as default quote format?](https://stackoverflow.com/questions/18283725/how-to-create-a-python-dictionary-with-double-quotes-as-default-quote-format) – BrokenBenchmark Apr 20 '22 at 23:16
  • 1
    Show us the code that creates the file. – John Gordon Apr 20 '22 at 23:20

2 Answers2

0

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?

lemon
  • 14,875
  • 6
  • 18
  • 38
0

You can use try this

import json

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

print(json.dumps(dic))
WindCheck
  • 374
  • 1
  • 9