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:52Victor MerckléVictor MerckléScore: 2,404Success
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 13:582,39030,935,21013,045,0008,706,00092,782,592stderr
2Aug 19, 2026 13:582,39430,933,60313,002,0008,785,00092,782,592stderr
3Aug 19, 2026 13:582,39830,933,85913,045,0008,781,00092,762,112stderr
4Aug 19, 2026 13:582,40030,841,77313,126,0008,721,00092,770,304stderr
5Aug 19, 2026 13:582,40430,903,89513,160,0008,719,00092,774,400stderr
6Aug 19, 2026 13:582,40630,918,32513,187,0008,710,00092,745,728stderr
7Aug 19, 2026 13:582,41631,050,78013,070,0008,923,00092,794,880stderr
8Aug 19, 2026 13:582,43331,137,62813,129,0009,013,00092,700,672stderr
9Aug 19, 2026 13:582,43431,186,75513,118,0009,035,00092,733,440stderr