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:23Victor MerckléVictor MerckléScore: 2,714Success
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:292,69733,305,70915,982,0008,562,00092,782,592stderr
2Sep 15, 2026 16:292,70935,867,17416,071,0008,582,00092,758,016stderr
3Sep 15, 2026 16:292,71234,059,31316,054,0008,632,00092,737,536stderr
4Sep 15, 2026 16:292,71334,105,56216,093,0008,596,00092,729,344stderr
5Sep 15, 2026 16:292,71433,439,44516,069,0008,631,00092,717,056stderr
6Sep 15, 2026 16:292,71533,400,26315,896,0008,813,00092,766,208stderr
7Sep 15, 2026 16:292,71734,169,14416,021,0008,704,00092,749,824stderr
8Sep 15, 2026 16:292,71833,530,50716,091,0008,650,00092,733,440stderr
9Sep 15, 2026 16:292,71933,397,31316,026,0008,720,00092,729,344stderr