Last active
June 8, 2025 16:57
-
-
Save bockor/6a6b74b89ec22a59d8a6e77023baa3a8 to your computer and use it in GitHub Desktop.
Convert a python dictionary into json format. Find and explain the errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| my_favorite = {"product": "Stella", "flavors": ["walnut", "prune"], "ranking": None, "price": 1.15, "in_stock": False } | |
| """ | |
| json.dumps() function converts a subset of Python objects into a json string. | |
| """ | |
| my_favorite_json = json.dumps(my_favorite , indent=2, sort_keys=True) | |
| print(my_favorite_json) | |
| """ | |
| { | |
| "flavors": [ | |
| "walnut", | |
| "prune" | |
| ], | |
| "in_stock": False, | |
| "price": "1.15", | |
| "product": "Stella", | |
| "ranking": None | |
| } | |
| Unexpected result here. Identfy end correct the four errors. | |
| Solution: | |
| { | |
| "flavors": [ | |
| "walnut", | |
| "prune" | |
| ], | |
| "in_stock": false, | |
| "price": 1.15, | |
| "product": "Stella", | |
| "ranking": null | |
| } | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment