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:08Victor MerckléVictor MerckléScore: 2,399Success
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:132,38430,136,49713,070,0008,625,00092,753,920stderr
2Aug 19, 2026 16:132,38630,102,07512,984,0008,731,00092,774,400stderr
3Aug 19, 2026 16:132,39130,044,59613,097,0008,670,00092,749,824stderr
4Aug 19, 2026 16:132,39930,730,75513,228,0008,605,00092,815,360stderr
5Aug 19, 2026 16:132,39930,867,29413,055,0008,782,00092,774,400stderr
6Aug 19, 2026 16:132,40630,254,46713,068,0008,830,00092,704,768stderr
7Aug 19, 2026 16:132,41330,374,80713,002,0008,960,00092,704,768stderr
8Aug 19, 2026 16:132,41330,312,98513,241,0008,721,00092,758,016stderr
9Aug 19, 2026 16:132,42031,039,39813,101,0008,925,00092,717,056stderr