0
dic = [{'one':1, 'two':'t', 'three': {'three.1': 3.1, 'three.2': '3.2' }}]

Desire Output,

[{"one":1, "two":"t", "three": {"three.1": 3.1, "three.2": "3.2" }}]

Tried Code:

ast.literal_eval(json.dumps(dic[0]))

here, Json converting the quotes but also changing the type to str. So I applied ast to change type. at end getting the same output with single quotes.

Output of Json.dumps: json.dumps(dic[0])

'{"one": 1, "two": "t", "three": {"three.1": 3.1, "three.2": "3.2"}}'

Above pre and post single quotes are the issue.

2 Answers2

0

Whats wrong with json.dumps(dic)?

bitflip
  • 3,436
  • 1
  • 3
  • 22
0

If you want to print the dictionary to terminal with double quotes, you can

>>> print(json.dumps(dic))
[{"one": 1, "two": "t", "three": {"three.1": 3.1, "three.2": "3.2"}}]
Tzane
  • 2,752
  • 1
  • 10
  • 21