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 16:14Victor MerckléVictor MerckléScore: 2,396Success
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 16:202,38930,174,10713,137,0008,608,00092,712,960stderr
2Aug 19, 2026 16:202,39130,172,52313,136,0008,624,00092,745,728stderr
3Aug 19, 2026 16:202,39130,739,78413,102,0008,658,00092,794,880stderr
4Aug 19, 2026 16:202,39430,825,90012,888,0008,905,00092,794,880stderr
5Aug 19, 2026 16:202,39630,801,78613,104,0008,705,00092,753,920stderr
6Aug 19, 2026 16:202,39730,829,13313,120,0008,697,00092,704,768stderr
7Aug 19, 2026 16:202,40230,253,32713,222,0008,640,00092,762,112stderr
8Aug 19, 2026 16:202,41230,885,30613,279,0008,672,00092,782,592stderr
9Aug 19, 2026 16:202,41931,003,53113,105,0008,910,00092,704,768stderr