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 2, 2026 15:51Victor MerckléVictor MerckléScore: 2,835Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Aug 2, 2026 15:572,82435,549,76817,161,0008,544,00092,712,960stderr
2Aug 2, 2026 15:572,82835,656,06017,119,0008,623,00092,762,112stderr
3Aug 2, 2026 15:572,83135,552,48717,205,0008,564,00092,721,152stderr
4Aug 2, 2026 15:572,83135,616,22617,174,0008,597,00092,737,536stderr
5Aug 2, 2026 15:572,83535,631,53417,181,0008,621,00092,766,208stderr
6Aug 2, 2026 15:572,84735,737,50117,306,0008,604,00092,749,824stderr
7Aug 2, 2026 15:572,85335,839,48617,281,0008,685,00092,692,480stderr
8Aug 2, 2026 15:572,85735,822,80617,199,0008,808,00092,749,824stderr
9Aug 2, 2026 15:572,86135,948,82717,331,0008,710,00092,733,440stderr