EasyPython

Standard Library — JSON Serialize & Parse

PythonJSONStandard Library

Implement solve(data, mode) using Python's json module:

  • "serialize" → convert the Python dict/list data to a JSON string (keys sorted alphabetically).
  • "parse" → parse the JSON string data and return the Python object.
  • "roundtrip" → serialize then immediately parse data and return the result (should equal the input).

Examples

  • solve({"name": "Alice", "age": 30}, "serialize")'{"age": 30, "name": "Alice"}'
  • solve('{"name": "Alice", "age": 30}', "parse"){"name": "Alice", "age": 30}

Sample tests

Test #1Serialize dict with sorted keys
Input: [{"age":30,"name":"Alice"},"serialize"]
Output: "{\"age\": 30, \"name\": \"Alice\"}"
Test #2Parse JSON string
Input: ["{\"name\": \"Alice\", \"age\": 30}","parse"]
Output: {"age":30,"name":"Alice"}
Test #3Serialize list
Input: [[1,2,3],"serialize"]
Output: "[1, 2, 3]"