Complete the code to convert a Python dictionary to a JSON string.
import json data = {"name": "Alice", "age": 30} json_string = json.[1](data) print(json_string)
The json.dumps() function converts a Python object into a JSON string.
Complete the code to convert a JSON string back to a Python dictionary.
import json json_string = '{"name": "Bob", "age": 25}' data = json.[1](json_string) print(data)
The json.loads() function parses a JSON string and returns a Python object.
Fix the error in the code to correctly write a Python dictionary to a JSON file.
import json data = {"city": "Paris", "population": 2148327} with open('data.json', 'w') as file: json.[1](data, file)
The json.dump() function writes a Python object as JSON into a file.
Fill both blanks to deserialize JSON from a file and print the Python object.
import json with open('info.json', 'r') as [1]: data = json.[2]([1]) print(data)
Open the file with a variable name (e.g., 'f') and use json.load() to read JSON from the file object.
Fill all three blanks to serialize a Python dictionary with indentation and sort keys.
import json person = {"name": "Eve", "age": 28, "city": "Berlin"} json_string = json.[1](person, indent=[2], sort_keys=[3]) print(json_string)
Use json.dumps() to convert to a JSON string with indentation (4 spaces) and keys sorted alphabetically (sort_keys=True).