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 listSep 15, 2026 16:03Victor MerckléVictor MerckléScore: 3,157Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 15, 2026 16:083,13738,890,67620,018,0008,532,00092,778,496stderr
2Sep 15, 2026 16:083,14639,705,02719,976,0008,653,00092,688,384stderr
3Sep 15, 2026 16:083,14739,148,05220,067,0008,573,00092,762,112stderr
4Sep 15, 2026 16:083,15439,001,03920,073,0008,635,00092,762,112stderr
5Sep 15, 2026 16:083,15739,810,11220,101,0008,636,00092,758,016stderr
6Sep 15, 2026 16:083,15939,059,23520,126,0008,623,00092,741,632stderr
7Sep 15, 2026 16:083,16039,111,54620,020,0008,743,00092,762,112stderr
8Sep 15, 2026 16:083,17039,080,90520,051,0008,799,00092,712,960stderr
9Sep 15, 2026 16:083,17239,190,86620,071,0008,795,00092,708,864stderr