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 listAug 19, 2026 13:59Victor MerckléVictor MerckléScore: 2,407Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Aug 19, 2026 14:052,38430,360,59913,048,0008,654,00092,782,592stderr
2Aug 19, 2026 14:052,39330,900,14112,950,0008,835,00092,721,152stderr
3Aug 19, 2026 14:052,39930,228,04313,236,0008,597,00092,745,728stderr
4Aug 19, 2026 14:052,40330,940,41312,990,0008,881,00092,741,632stderr
5Aug 19, 2026 14:052,40730,922,91613,122,0008,790,00092,717,056stderr
6Aug 19, 2026 14:052,41330,236,67813,064,0008,900,00092,721,152stderr
7Aug 19, 2026 14:052,42031,028,33013,013,0009,011,00092,774,400stderr
8Aug 19, 2026 14:052,42330,394,91313,000,0009,055,00092,774,400stderr
9Aug 19, 2026 14:052,42430,452,80913,554,0008,508,00092,782,592stderr