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 listApr 22, 2026 20:39Charles CabergsCharles CabergsScore: 5,003Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2026 20:414,98162,463,57730,224,00015,112,00094,613,504
2Apr 22, 2026 20:414,98761,573,03230,257,00015,128,00094,789,632
3Apr 22, 2026 20:414,99365,046,32728,277,00017,168,00094,793,728
4Apr 22, 2026 20:415,00164,590,85729,332,00016,183,00094,609,408
5Apr 22, 2026 20:415,00365,723,14026,726,00018,807,00094,789,632
6Apr 22, 2026 20:415,01565,884,83829,415,00016,229,00094,797,824
7Apr 22, 2026 20:415,01765,141,66928,784,00016,873,00094,613,504
8Apr 22, 2026 20:415,01965,043,87829,436,00016,240,00094,793,728
9Apr 22, 2026 20:415,02465,329,64630,811,00014,908,00094,609,408