Skip to content

Instantly share code, notes, and snippets.

@bockor
Last active June 8, 2025 16:57
Show Gist options
  • Save bockor/6a6b74b89ec22a59d8a6e77023baa3a8 to your computer and use it in GitHub Desktop.
Save bockor/6a6b74b89ec22a59d8a6e77023baa3a8 to your computer and use it in GitHub Desktop.
Convert a python dictionary into json format. Find and explain the errors
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