Data formats: XML, INI, TOML and pickle · 13 / 15 Exercise Hard

From TOML to JSON

Objective

Data coming from outside can be invalid. tomllib.loads raises TOMLDecodeError if the TOML text is malformed, and a robust program must catch it.

Instructions

  • The first line has the number n of lines; then come those lines of a TOML document.
  • If it is valid, show its content as JSON with json.dumps(data, sort_keys=True) (on one line). Otherwise show Invalid TOML.
Input
3
nombre = "ana"
edad = 30
notas = [7, 9]
Output
{"edad": 30, "nombre": "ana", "notas": [7, 9]}

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise