XML to JSON Sergey Svistunov

Convert 1,000,000 person records from XML to JSON as fast as possible.

Input

XML document on STDIN:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
    <person id="1512376">
        <age>30</age>
        <height>169.1</height>
        <married>true</married>
        <phone code="+6"><number>1283603279</number></phone>
        <phone code="+6"><number>1659964668</number></phone>
    </person>
    ...
</persons>

Output

One JSON object per person to STDOUT, preserving order:

{
    "id": 1512376,
    "age": 30,
    "height": 169.1,
    "married": true,
    "phones": [
        {
            "code": "+6",
            "number": 1283603279
        },
        {
            "code": "+6",
            "number": 1659964668
        }
    ]
}

Constraints

  • Preserve the order of persons
  • Omit the phones field if the phone array is empty
  • Maximum number of phones per person is 3
Back to listJun 5, 2026 16:43Victor MerckléVictor MerckléError
Source Code

Source code access is restricted. Log in to request access.

Challenge History
DateChallengerCostTypeStatus
Sep 4, 2026 22:29Tomislav Tunkovic10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 4, 2026 22:34023,035,7988,285,0004,583,00041,803,776invalid character '"' after object key:value pair
2Sep 4, 2026 22:34022,697,3758,305,0004,550,00041,783,296invalid character 's' looking for beginning of value
3Sep 4, 2026 22:34022,674,9838,258,0004,562,00041,799,680diff: map[string]any{ "age": s"20", - "height": s"167.8", + "height": s"197.8", "id": s"673905", "married": bool(false), - "phones": []any{map[string]any{"code": string("+3"), "number": s"1642129358"}}, }
4Jun 5, 2026 16:492,84034,886,67817,167,0008,678,00092,737,536
5Jun 5, 2026 16:492,84235,000,48117,327,0008,544,00092,745,728
6Jun 5, 2026 16:492,84434,925,88617,192,0008,695,00092,766,208
7Jun 5, 2026 16:492,85835,053,28617,400,0008,611,00092,733,440
8Jun 5, 2026 16:492,85935,072,60317,423,0008,594,00092,680,192
9Jun 5, 2026 16:492,86235,153,55517,439,0008,606,00092,745,728
10Jun 5, 2026 16:492,86835,150,19617,420,0008,679,00092,790,784
11Jun 5, 2026 16:492,86835,211,99417,432,0008,667,00092,815,360
12Jun 5, 2026 16:492,87435,248,90517,365,0008,794,00092,737,536