0

I have the following json file:

{
   "company":[
      {
         "name":"My company",
         "security":"WPA2-PSK"
      }
   ],
   "name":"one name"
}

When I do:

j = open(file)
j1 = json.load(j)
j.close()
j2 = json.dumps(j1)
#type(j2)
j3 = json.loads(j2)

I have the following dictionary:

{'company': [{'name': 'My company', 'security': 'WPA2-PSK'}],
 'name': 'one name'}

But I need a dictionary with double quotes like this:

{"company": [{"name": "My company", "security": "WPA2-PSK"}],
     "name": "one name"}
Beto
  • 579
  • 1
  • 5
  • 15
  • What you have and what you "need" is identical. Strings can be represented with single and double quotes interchangably in Python. – mkrieger1 Nov 10 '21 at 13:51
  • I'm voting to close this as duplicate of [Convert single-quoted string to double-quoted string](https://stackoverflow.com/questions/1906991/convert-single-quoted-string-to-double-quoted-string) – mkrieger1 Nov 10 '21 at 13:53
  • `j3` is a dictionary now and that is just how they `print()` by default. If you want to see the json text that represents that dictionary then go back to `j2` – JonSG Nov 10 '21 at 13:55
  • I need to send a dictionary as json to an API. I need a dictionary with double quotes. – Beto Nov 10 '21 at 14:00

0 Answers0