Sort top-level keys
Input
json_sorted({'b': 2, 'a': 1})
Output
{"a": 1, "b": 2}
Top-level object keys are sorted alphabetically in the resulting JSON string.
Full lesson preview
Convert Python objects to JSON strings with object keys sorted for deterministic output.
Problem statement
Task
Examples
Input
json_sorted({'b': 2, 'a': 1})
Output
{"a": 1, "b": 2}
Top-level object keys are sorted alphabetically in the resulting JSON string.
Input format
Output format
Constraints
Samples
Input
json_sorted({'b':1, 'a':2})
Output
{"a": 2, "b": 1}
Keys 'a' and 'b' are ordered in the output string.