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 listMay 18, 2026 07:20M-RochatM-RochatError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 10:09Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 10:10052,666,55534,872,0008,398,00092,893,184invalid character '<' after object key:value pair
2Jul 6, 2026 10:10052,624,57434,897,0008,370,00092,893,184invalid character '<' after object key:value pair
3Jul 6, 2026 10:10052,841,49734,992,0008,541,00092,893,184invalid character '<' after object key:value pair
4May 18, 2026 07:334,95555,661,03836,769,0008,330,00092,733,440
5May 18, 2026 07:334,96954,281,71136,813,0008,409,00092,762,112
6May 18, 2026 07:334,97254,422,82436,816,0008,430,00092,672,000
7May 18, 2026 07:334,97355,423,97936,834,0008,426,00092,803,072
8May 18, 2026 07:334,97556,790,42236,948,0008,328,00092,737,536
9May 18, 2026 07:334,97654,821,83936,807,0008,476,00092,762,112
10May 18, 2026 07:334,97954,911,09336,837,0008,478,00092,712,960
11May 18, 2026 07:334,98054,628,61636,805,0008,517,00092,782,592
12May 18, 2026 07:334,98656,499,93336,969,0008,405,00092,758,016