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:15Victor MerckléVictor MerckléScore: 2,710Success
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:202,70234,002,19616,021,0008,573,00092,766,208stderr
2Sep 15, 2026 16:202,70733,389,24816,016,0008,622,00092,798,976stderr
3Sep 15, 2026 16:202,71034,058,41616,054,0008,607,00092,712,960stderr
4Sep 15, 2026 16:202,71034,033,61916,042,0008,619,00092,819,456stderr
5Sep 15, 2026 16:202,71033,367,88916,034,0008,629,00092,741,632stderr
6Sep 15, 2026 16:202,71233,423,94315,874,0008,814,00092,741,632stderr
7Sep 15, 2026 16:202,71334,031,92816,035,0008,656,00092,753,920stderr
8Sep 15, 2026 16:202,71934,110,77616,047,0008,702,00092,725,248stderr
9Sep 15, 2026 16:202,72033,468,36016,046,0008,710,00092,733,440stderr