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 16, 2026 13:31Victor MerckléVictor MerckléScore: 2,740Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 16, 2026 13:372,72933,541,52916,174,0008,660,00092,725,248stderr
2Sep 16, 2026 13:372,73434,370,91016,233,0008,650,00092,782,592stderr
3Sep 16, 2026 13:372,73733,682,85616,239,0008,673,00092,782,592stderr
4Sep 16, 2026 13:372,73733,620,36716,206,0008,708,00092,766,208stderr
5Sep 16, 2026 13:372,74033,739,78516,190,0008,753,00092,758,016stderr
6Sep 16, 2026 13:372,74133,720,94016,236,0008,708,00092,749,824stderr
7Sep 16, 2026 13:372,75042,558,01516,259,0008,768,00092,737,536stderr
8Sep 16, 2026 13:372,75134,483,41316,215,0008,823,00092,790,784stderr
9Sep 16, 2026 13:372,75433,838,96216,248,0008,817,00092,725,248stderr